Example #1
0
import helpFunctions as hF

input = hF.txt2Table("aoc5.txt")


def split_list(a_list):
    half = len(a_list) // 2
    return a_list[:half], a_list[half:]


def getSeat(s):
    rows = range(128)
    columns = range(8)

    for char in s[:-3]:
        if (char == "F"):
            rows = split_list(rows)[0]
        if (char == "B"):
            rows = split_list(rows)[1]

    for char in s[-4:]:
        if (char == "L"):
            columns = split_list(columns)[0]
        if (char == "R"):
            columns = split_list(columns)[1]

    return (rows[0], columns[0], rows[0] * 8 + columns[0])


def getMySeat(seats):
    validseats = set()
Example #2
0
import helpFunctions as hF

input = hF.txt2Table("aoc1.txt", int)

for i in input:
    for j in input:
        for k in input:
            if (i + j + k == 2020):
                print(i*j*k)
Example #3
0
import helpFunctions as hF

input = hF.txt2Table("aoc6.txt")

answers = []
tmp = ""
for line in input:
    line.replace("\n", "")
    if (line == ""):
        answers.append(tmp)
        tmp = ""
        continue
    tmp += line

if tmp != "":
    answers.append(tmp)
print(answers)


def getDiffAnsCount(answers):
    diffanswers = set()
    for a in answers:
        if a != " " and a != "\n":
            diffanswers.add(a)
    # print(diffanswers, len(diffanswers))
    return len(diffanswers)


def getSameAnsCount(answers):
    count = 0
    for group in answers:
Example #4
0
# -*- coding: utf-8 -*-
"""
Created on Tue Dec  3 21:19:19 2019

@author: akrauhan
"""
from helpFunctions import txt2Table


def str2Tuple(string):
    return (string[0], string[1:])


wiresAsStrings = txt2Table("aoc3.txt")
frstWireUnsplit = wiresAsStrings[0].split(",")
scndWireUnsplit = wiresAsStrings[1].split(",")

frstWire = [(x[0], int(x[1:])) for x in frstWireUnsplit]
scndWire = [(x[0], int(x[1:])) for x in scndWireUnsplit]


def pointsPassed(wire):
    x = 0
    y = 0
    l = 0
    points = {}
    for i in range(0, len(wire)):
        if wire[i][0] == "R":
            for j in range(0, wire[i][1]):
                x += 1
                l += 1
Example #5
0
    return (min <= counter and counter <= max)


def isValid2(password):
    password = password.split(":")
    rules = password[0].split("-")
    first = int(rules[0])
    req = rules[1][-1]
    last = int(rules[1][:-1])

    c = 0
    for i in (first, last):
        if password[1][i] == req:
            c += 1

    return (c == 1)


input = hF.txt2Table("aoc2.txt")

print(isValid2("9-12 q: qqqqqpqrqqlcq"))
print(isValid2("2-3 r: vxnw"))

counter = 0
for pw in input:
    if isValid2(pw):
        counter += 1

print(counter)
Example #6
0
            ]:
                return False
            c += 1
            print("Valid: ", field)
        if field == "pid":
            if len(fieldInfo) != 9:
                return False
            for no in fieldInfo:
                if int(no) not in range(10):
                    return False
            c += 1
            print("Valid: ", field)
    return c == 7


input = hF.txt2Table("aoc4.txt")

passports = []
tmp = ""
for line in input:
    if (line == "\n"):
        passports.append(tmp)
        tmp = ""
        continue
    tmp += line.replace("\n", " ")

c = 0
for passport in passports:
    valid = isValid(passport)
    if valid:
        c += 1
Example #7
0
import helpFunctions as hF

input = hF.txt2Table("aoc3.txt")


def treesWhenSlope(right, down):
    c = 0
    row = 0
    col = 0
    row_length = len(input[0])

    while (row < len(input)):
        if (input[row][col] == "#"):
            c += 1

        row += down
        col = (col + right) % (row_length - 1)
    print("Right " + str(right) + ", Down ", str(down), ":", c)
    return (c)


prod = 1
prod *= treesWhenSlope(1, 2)
for i in range(1, 8, 2):
    prod *= treesWhenSlope(i, 1)

print(prod)
Example #8
0
# -*- coding: utf-8 -*-
"""
Created on Mon Dec  2 20:09:39 2019

@author: akrauhan
"""
import math
from helpFunctions import txt2Table

puzzleInput = txt2Table("aoc1.txt", int)

def fuelForModule(m):
    '''Fuel for module with mass of m.'''
    return math.floor(m/3) - 2

fuels = map(fuelForModule, puzzleInput)
sumOfFuels = sum(fuels)

print(sumOfFuels) # Task 1 correct.

def fuelForFuel(m):
    '''Fuel for module or fuel with mass m'''
    mbyFuelMass = math.floor(m/3) - 2
    if (mbyFuelMass <= 0): return 0
    return mbyFuelMass + fuelForFuel(mbyFuelMass)

fuels2 = map(fuelForFuel, puzzleInput)
sumOfFuels2 = sum(fuels2)

print(fuelForFuel(14)) ## Test: 2
print(fuelForFuel(48)) ## Test: 16