Exemplo n.º 1
0
def get_data(test=False):
    if test:
        input_file = AOCInput(filename='test_input.txt')
        data = input_file.get_input
    else:
        input_file = AOCInput()
        data = input_file.get_input
    data_out = dict()
    for line in data:
        a, b = line.split('contain')
        a = a.replace('bags', "")
        b = b.strip(' ')
        if b == 'no other bags.':
            data_out[a] = 0
        else:
            c = b.split(',')
            d = dict()
            for item in c:
                item = item.strip('.')
                item = item.strip('bags')
                num = int(item[0:2])
                item = item[2:]
                d[item.strip(' ')] = num
            data_out[a.strip(' ')] = d
    return data_out
Exemplo n.º 2
0
def get_data(fn: str) -> list:
    data_in = AOCInput(filename=fn)
    data = data_in.get_input
    logger.debug(f'data = {data}')
    #insert logic to change data as necessary
    output = [int(x) for x in data]
    return output
Exemplo n.º 3
0
def test1() -> bool:
    '''
    tests the program for the first puzzle against the test input given on the page
    to make sure I get same answer as that is given on adventofcode.com
    '''
    test = AOCInput(filename='test_input.txt')
    test_input = tuple(test.get_input)
    ans = ans1(test_input)
    return ans == 7
Exemplo n.º 4
0
def test2(slopes: tuple) -> bool:
    '''
    tests the program for the first puzzle against the test input given on the page
    to make sure I get same answer as that is given on adventofcode.com
    '''
    test = AOCInput(filename='test_input.txt')
    test_input = tuple(test.get_input)
    lst = []
    ans = 1
    for slope in slopes:
        appending = ans2(test_input, slope[0], slope[1])
        lst.append(appending)
    for num in lst:
        ans *= num
    return ans == 336
Exemplo n.º 5
0
def main():
    puzzle_input = AOCInput()
    if test1() is True:
        print(f'Answer for puzzle one is {ans1(puzzle_input.get_input)}')
    else:
        print('Test1 failed')
    slopes = ((1, 1), (3, 1), (5, 1), (7, 1), (1, 2))
    if test2(slopes) is True:
        lst_of_nums = []
        for slope in slopes:
            lst_of_nums.append(ans2(puzzle_input.get_input, slope[0],
                                    slope[1]))
        ans_2 = 1
        for num in lst_of_nums:
            ans_2 *= num
        print(f'Answer for puzzled two is {ans_2}')
    else:
        print(f'Test2 failed.')
Exemplo n.º 6
0
def get_data(fn: str) -> list:
    data_in  = AOCInput(filename=fn)
    data = data_in.get_input
    # insert logic to change data as necessary
    output = [(x[0:1],int(x[1:])) for x in data ]
    return output
Exemplo n.º 7
0
from aoc_input import AOCInput
from pprint import pprint
puzzle_input = AOCInput()
test_input = AOCInput(filename='test_input.txt')


def my_zip(list1, list2):
    output = []
    for item1 in list1:
        for item2 in list2:
            output.append((item1, item2))
    return tuple(output)


def ans(data):
    seat_ids = []
    rows_cols = my_zip(list(range(128)), list(range(8)))
    all_possible_seat_ids = [x * 8 + y for x, y in rows_cols]
    missing_ids = []
    for boarding_pass in data:
        rows = list(range(128))
        cols = list(range(8))
        first_seven = boarding_pass[:7]
        for character in first_seven:
            if character == "F":
                rows = rows[:len(rows) // 2]
            elif character == 'B':
                rows = rows[len(rows) // 2:]
        last_three = boarding_pass[-3:]
        for character in last_three:
            if character == 'R':
Exemplo n.º 8
0
def get_data(fn: str) -> list:
    data_in = AOCInput(filename=fn)
    data = data_in.get_input
    # insert logic to change data as necessary
    return [int(x) for x in data]
Exemplo n.º 9
0
def get_data(fn: str) -> tuple:
    data_in = AOCInput(filename=fn)
    data = data_in.get_input
    # insert logic to change data as necessary
    return int(data[0]), tuple(
        [int(x) for x in data[1].split(',') if x != 'x'])
Exemplo n.º 10
0
        letter = line[1][0:1]
        password = line[2]
        yield (int(min_letter) , int(max_letter), letter, password)

def ans_2(list_in: list) -> int:
    num_valid = 0
    for first_letter, second_letter, letter, pw in str_generator(list_in):
        pos_1 = pw[first_letter - 1]
        pos_2 = pw[second_letter - 1]
        if  (pos_1 == letter or  pos_2 == letter) and pos_1 != pos_2:
            num_valid += 1
    return num_valid

def test_ans1() -> bool:
    test_input = ['1-3 a: abcde', '1-3 b: cdefg', '2-9 c: ccccccccc']
    return ans_1(test_input) == 2

def test_ans2() -> bool:
    test_input = ['1-3 a: abcde', '1-3 b: cdefg', '2-9 c: ccccccccc']
    return ans_2(test_input) == 1

if __name__ == "__main__":
    if test_ans1():
        puzzle_input = AOCInput(filename='puzzle_input.txt')
        print(f'\nAnswer for puzzle one is {ans_1(puzzle_input.get_input)}\n')
    else:
        print(f'test of ans_1() failed.')
    if test_ans2():
        print(f'Answer for puzzle two is {ans_2(puzzle_input.get_input)}\n')
    else:
        print("test of ans_2() failed.")
Exemplo n.º 11
0
def get_data(fn: str) -> list:
    data_in = AOCInput(filename=fn)
    data = data_in.get_input
    # insert logic to change data as necessary
    output = data
    return output