Пример #1
0
        raise Exception(f"Test 2.3 did not past, got {result_2}")

    test_inputs = """
    ((2 + 4 * 9) * (6 + 9 * 8 + 6) + 6) + 2 + 4 * 2
    """.strip().split('\n')

    result_2 = run_2(test_inputs)
    if result_2 != 23340:
        raise Exception(f"Test 2.4 did not past, got {result_2}")

    test_inputs = """
    2 * 3 + (4 * 5)
    2 * 3 + (4 * 5)
    """.strip().split('\n')

    result_2 = run_2(test_inputs)
    if result_2 != 92:
        raise Exception(f"Test 2.5 did not past, got {result_2}")


if __name__ == "__main__":
    run_tests()

    input = read_inputs(18)

    result_1 = run_1(input)
    print(f"Finished 1 with result {result_1}")

    result_2 = run_2(input)
    print(f"Finished 2 with result {result_2}")
Пример #2
0

def run_tests():
    test_inputs = """
    389125467
    """.strip().split('\n')

    result_1 = run_1(test_inputs, 10)
    if result_1 != '92658374':
        raise Exception(f"Test 0 did not past, got {result_1}")

    result_1 = run_1(test_inputs, 100)
    if result_1 != '67384529':
        raise Exception(f"Test 1 did not past, got {result_1}")

    result_2 = run_2(test_inputs)
    if result_2 != 149245887792:
        raise Exception(f"Test 2 did not past, got {result_2}")


if __name__ == "__main__":
    run_tests()

    input = read_inputs(23)

    result_1 = run_1(input, 100)
    print(f"Finished 1 with result {result_1}")

    result_2 = run_2(input)
    print(f"Finished 2 with result {result_2}")
Пример #3
0
    mem[7] = 101
    mem[8] = 0
    """.strip().split('\n')

    result_1 = run_1(test_inputs)
    if result_1 != 165:
        raise Exception(f"Test 1 did not past, got {result_1}")

    test_inputs = """
    mask = 000000000000000000000000000000X1001X
    mem[42] = 100
    mask = 00000000000000000000000000000000X0XX
    mem[26] = 1
    """.strip().split('\n')

    result_2 = run_2(test_inputs)
    if result_2 != 208:
        raise Exception(f"Test 2 did not past, got {result_2}")


if __name__ == "__main__":
    run_tests()

    input = read_inputs(14)

    result_1 = run_1(input)
    print(f"Finished 1 with result {result_1}")

    result_2 = run_2(input)
    print(f"Finished 2 with result {result_2}")
Пример #4
0
    ..#.#...#.#
    .#...##..#.
    ..#.##.....
    .#.#.#....#
    .#........#
    #.##...#...
    #...##....#
    .#..#...#.#
    """
    test_inputs = [i.strip() for i in input_str.strip().split('\n')]

    result_1 = run_1(test_inputs)
    if result_1 != 7:
        raise Exception(f"Test 1 did not past, got {result_1}")

    result_2 = run_2(test_inputs)
    if result_2 != 336:
        raise Exception(f"Test 2 did not past, got {result_2}")


if __name__ == "__main__":
    run_tests()

    input = [i.strip() for i in read_inputs(3)]

    result_1 = run_1(input)
    print(f"Finished 1 with result {result_1}")

    result_2 = run_2(input)
    print(f"Finished 2 with result {result_2}")
Пример #5
0

def run_tests():
    test_inputs = """
    F10
    N3
    F7
    R90
    F11
    """.strip().split('\n')

    result_1 = run_1(test_inputs)
    if result_1 != 25:
        raise Exception(f"Test 1 did not past, got {result_1}")

    result_2 = run_2(test_inputs)
    if result_2 != 286:
        raise Exception(f"Test 2 did not past, got {result_2}")


if __name__ == "__main__":
    run_tests()

    input = read_inputs(12)

    result_1 = run_1(input)
    print(f"Finished 1 with result {result_1}")

    result_2 = run_2(input)
    print(f"Finished 2 with result {result_2}")
Пример #6
0
    ######....
    ####.#..#.
    .#...#.##.
    #.#####.##
    ..#.###...
    ..#.......
    ..#.###...
    """.strip().split('\n')

    result_1 = run_1(test_inputs)
    if result_1 != 20899048083289:
        raise Exception(f"Test 1 did not past, got {result_1}")
    print("Test 1 passed")

    result_2 = run_2(test_inputs)
    if result_2 != 273:
        raise Exception(f"Test 2 did not past, got {result_2}")
    print("Test 2 passed")


if __name__ == "__main__":
    run_tests()

    input = read_inputs(20)

    result_1 = run_1(input)
    print(f"Finished 1 with result {result_1}")

    result_2 = run_2(input)
    print(f"Finished 2 with result {result_2}")
Пример #7
0
    positions = {(0, 0, 0): '.', (0, 1, 0): '#', (0, 2, 0): '.', (1, 0, 0): '.', (1, 1, 0): '.', (1, 2, 0): '#', (2, 0, 0): '#', (2, 1, 0): '#', (2, 2, 0): '#'}
    expected = [((-1, -1, -1), '.'), ((-1, -1, 0), '.'), ((-1, -1, 1), '.'), ((-1, 0, -1), '.'), ((-1, 0, 0), '.'), ((-1, 0, 1), '.'), ((-1, 1, -1), '.'), ((-1, 1, 0), '.'), ((-1, 1, 1), '.'), ((0, -1, -1), '.'), ((0, -1, 0), '.'), ((0, -1, 1), '.'), ((0, 0, -1), '.'), ((0, 0, 1), '.'), ((0, 1, -1), '.'), ((0, 1, 0), '#'), ((0, 1, 1), '.'), ((1, -1, -1), '.'), ((1, -1, 0), '.'), ((1, -1, 1), '.'), ((1, 0, -1), '.'), ((1, 0, 0), '.'), ((1, 0, 1), '.'), ((1, 1, -1), '.'), ((1, 1, 0), '.'), ((1, 1, 1), '.')]
    if get_neighbors((0,0,0), positions) != expected:
        raise Exception("get_neighbors test did not pass")

    test_inputs = """
    .#.
    ..#
    ###
    """.strip().split('\n')

    result_1 = run_1(test_inputs)
    if result_1 != 112:
        raise Exception(f"Test 1 did not past, got {result_1}")

    result_2 = run_2(test_inputs)
    if result_2 != 848:
        raise Exception(f"Test 2 did not past, got {result_2}")


if __name__ == "__main__":
    run_tests()

    input = read_inputs(17)

    result_1 = run_1(input)
    print(f"Finished 1 with result {result_1}")

    result_2 = run_2(input)
    print(f"Finished 2 with result {result_2}")
Пример #8
0
        else:
            possible_items = possible_items[midpoint:]
    return possible_items[0] if letters[-1] == keep_lower_letter else possible_items[1]


def run_tests():

    res1 = get_seat_id("BFFFBBFRRR")
    if res1 != 567:
        raise Exception(f"Test BFFFBBFRRR did not past, got {res1}")

    res2 = get_seat_id("FFFBBBFRRR")
    if res2 != 119:
        raise Exception(f"Test FFFBBBFRRR did not past, got {res2}")

    res3 = get_seat_id("BBFFBBFRLL")
    if res3 != 820:
        raise Exception(f"Test BBFFBBFRLL did not past, got {res3}")


if __name__ == "__main__":
    run_tests()

    input = read_inputs(5)

    result_1 = run_1(input)
    print(f"Finished 1 with result {result_1}")

    result_2 = run_2(input)
    print(f"Finished 2 with result {result_2}")
Пример #9
0
    ababaaaaabbbaba
    baabbaaaabbaaaababbaababb
    abbbbabbbbaaaababbbbbbaaaababb
    aaaaabbaabaaaaababaa
    aaaabbaaaabbaaa
    aaaabbaabbaaaaaaabbbabbbaaabbaabaaa
    babaaabbbaaabaababbaabababaaab
    aabbbbbaabbbaaaaaabbbbbababaaaaabbaaabba
    """.strip().split('\n')

    result_2 = run_2(test_inputs)
    if result_2 != 12:
        raise Exception(f"Test 2 did not past, got {result_2}")
    print("tests passed")


if __name__ == "__main__":
    run_tests()

    input = read_inputs(19)

    result_1 = run_1(input)
    print(f"Finished 1 with result {result_1}")
    # not 370
    # 365 too high
    # 355 too high
    # 348 is incorrect
    # 343 is incorrect
    result_2 = run_2(input)
    print(f"Finished 2 with result {result_2}")
Пример #10
0
    nop +0
    acc +1
    jmp +4
    acc +3
    jmp -3
    acc -99
    acc +1
    jmp -4
    acc +6
    """.strip().split('\n')

    result_1 = run_1(test_inputs)
    if result_1 != 5:
        raise Exception(f"Test 1 did not past, got {result_1}")

    result_2 = run_2(test_inputs)
    if result_2 != 8:
        raise Exception(f"Test 2 did not past, got {result_2}")


if __name__ == "__main__":
    run_tests()

    input = read_inputs(8)

    result_1 = run_1(input)
    print(f"Finished 1 with result {result_1}")

    result_2 = run_2(input)
    print(f"Finished 2 with result {result_2}")
Пример #11
0
    enewnwewneswsewnwswenweswnenwsenwsw
    sweneswneswneneenwnewenewwneswswnese
    swwesenesewenwneswnwwneseswwne
    enesenwswwswneneswsenwnewswseenwsese
    wnwnesenesenenwwnenwsewesewsesesew
    nenewswnwewswnenesenwnesewesw
    eneswnwswnwsenenwnwnwwseeswneewsenese
    neswnwewnwnwseenwseesewsenwsweewe
    wseweeenwnesenwwwswnew
    """.strip().split('\n')

    result_1 = run_1(test_inputs)
    if result_1 != 10:
        raise Exception(f"Test 1 did not past, got {result_1}")

    result_2 = run_2(test_inputs)
    if result_2 != 2208:
        raise Exception(f"Test 2 did not past, got {result_2}")


if __name__ == "__main__":
    run_tests()

    input = read_inputs(24)

    result_1 = run_1(input)
    print(f"Finished 1 with result {result_1}")

    result_2 = run_2(input)
    print(f"Finished 2 with result {result_2}")
Пример #12
0
    pid:087499704 hgt:74in ecl:grn iyr:2012 eyr:2030 byr:1980
    hcl:#623a2f

    eyr:2029 ecl:blu cid:129 byr:1989
    iyr:2014 pid:896056539 hcl:#a97842 hgt:165cm

    hcl:#888785
    hgt:164cm byr:2001 iyr:2015 cid:88
    pid:545766238 ecl:hzl
    eyr:2022

    iyr:2010 hgt:158cm hcl:#b6652a ecl:blu byr:1944 eyr:2021 pid:093154719
    """.strip().split('\n')

    result_2 = run_2(test_inputs_2)
    if result_2 != 4:
        raise Exception(f"Test 2 did not past, got {result_2}")


if __name__ == "__main__":
    run_tests()

    input = read_inputs(4)

    result_1 = run_1(input)
    print(f"Finished 1 with result {result_1}")

    result_2 = run_2(input)
    print(f"Finished 2 with result {result_2}")
Пример #13
0
    result_2 = run_2(test_inputs)
    if result_2 != 32:
        raise Exception(f"Test 2 did not past, got {result_2}")

    test_inputs2 = """
    shiny gold bags contain 2 dark red bags.
    dark red bags contain 2 dark orange bags.
    dark orange bags contain 2 dark yellow bags.
    dark yellow bags contain 2 dark green bags.
    dark green bags contain 2 dark blue bags.
    dark blue bags contain 2 dark violet bags.
    dark violet bags contain no other bags.
    """.strip().split('\n')

    result_3 = run_2(test_inputs2)
    if result_3 != 126:
        raise Exception(f"Test 3 did not past, got {result_3}")


if __name__ == "__main__":
    run_tests()

    input = read_inputs(7)

    result_1 = run_1(input)
    print(f"Finished 1 with result {result_1}")

    result_2 = run_2(input)
    print(f"Finished 2 with result {result_2}")
Пример #14
0
        raise Exception(f"Test 1.2 did not past, got {result_1}")

    result_1 = get_loop(17807724)
    if result_1 != 11:
        raise Exception(f"Test 1.3 did not past, got {result_1}")

    test_inputs = """
    5764801
    17807724
    """.strip().split('\n')

    result_1 = run_1(test_inputs)
    if result_1 != 14897079:
        raise Exception(f"Test 1 did not past, got {result_1}")

    # result_2 = run_2(test_inputs)
    # if result_2 != 0:
    #     raise Exception(f"Test 2 did not past, got {result_2}")


if __name__ == "__main__":
    run_tests()

    input = read_inputs(25)

    result_1 = run_1(input)
    print(f"Finished 1 with result {result_1}")

    # result_2 = run_2(input)
    # print(f"Finished 2 with result {result_2}")
Пример #15
0
    return ingredients, allergens


def run_tests():
    test_inputs = """
    mxmxvkd kfcds sqjhc nhms (contains dairy, fish)
    trh fvjkl sbzzf mxmxvkd (contains dairy)
    sqjhc fvjkl (contains soy)
    sqjhc mxmxvkd sbzzf (contains fish)
    """.strip().split('\n')

    result_1 = run_1(test_inputs)
    if result_1 != 5:
        raise Exception(f"Test 1 did not past, got {result_1}")

    result_2 = run_2(test_inputs)
    if result_2 != 'mxmxvkd,sqjhc,fvjkl':
        raise Exception(f"Test 2 did not past, got {result_2}")


if __name__ == "__main__":
    run_tests()

    input = read_inputs(21)

    result_1 = run_1(input)
    print(f"Finished 1 with result {result_1}")

    result_2 = run_2(input)
    print(f"Finished 2 with result {result_2}")
Пример #16
0
    8
    17
    7
    9
    4
    2
    34
    10
    3
    """.strip().split('\n')

    result_1 = run_1(test_inputs)
    if result_1 != 220:
        raise Exception(f"Test 1.2 did not past, got {result_1}")

    result_2 = run_2(test_inputs)
    if result_2 != 19208:
        raise Exception(f"Test 2.2 did not past, got {result_2}")


if __name__ == "__main__":
    run_tests()

    input = read_inputs(10)

    result_1 = run_1(input)
    print(f"Finished 1 with result {result_1}")

    result_2 = run_2(input)
    print(f"Finished 2 with result {result_2}")
Пример #17
0
    result_2 = run_2(test_inputs)
    if result_2 != 291:
        raise Exception(f"Test 2 did not past, got {result_2}")

    test_inputs = """
    Player 1:
    43
    19

    Player 2:
    2
    29
    14
    """.strip().split('\n')
    # Just make sure it doesn't infinitely loop
    run_2(test_inputs)

    print("tests passed")


if __name__ == "__main__":
    run_tests()

    input = read_inputs(22)

    result_1 = run_1(input)
    print(f"Finished 1 with result {result_1}")

    result_2 = run_2(input)
    print(f"Finished 2 with result {result_2}")
Пример #18
0
    test_inputs = """
    class: 0-1 or 4-19
    row: 0-5 or 8-19
    seat: 0-13 or 16-19

    your ticket:
    11,12,13

    nearby tickets:
    3,9,18
    15,1,5
    5,14,9
    """.strip().split('\n')

    result_2 = parse_my_ticket(test_inputs)
    if result_2 != {'class': 12, 'row': 11, 'seat': 13}:
        raise Exception(f"Test 2 did not past, got {result_2}")


if __name__ == "__main__":
    run_tests()

    input = read_inputs(16)
    result_1 = run_1(input)
    print(f"Finished 1 with result {result_1}")

    input = read_inputs(16)
    result_2 = run_2(input)
    print(f"Finished 2 with result {result_2}")
Пример #19
0
    117
    150
    182
    127
    219
    299
    277
    309
    576
    """.strip().split('\n')

    result_1 = run_1(test_inputs, 5)
    if result_1 != 127:
        raise Exception(f"Test 1 did not past, got {result_1}")

    result_2 = run_2(test_inputs, 5)
    if result_2 != 62:
        raise Exception(f"Test 2 did not past, got {result_2}")


if __name__ == "__main__":
    run_tests()

    input = read_inputs(9)

    result_1 = run_1(input, 25)
    print(f"Finished 1 with result {result_1}")

    result_2 = run_2(input, 25)
    print(f"Finished 2 with result {result_2}")
Пример #20
0
    result_2 = run_2([0, "67,7,59,61"])
    if result_2 != 754018:
        raise Exception(f"Test 2.2 did not pass, got {result_2}")

    result_2 = run_2([0, "67,x,7,59,61"])
    if result_2 != 779210:
        raise Exception(f"Test 2.3 did not pass, got {result_2}")

    result_2 = run_2([0, "67,7,x,59,61"])
    if result_2 != 1261476:
        raise Exception(f"Test 2.4 did not pass, got {result_2}")

    result_2 = run_2([0, "1789,37,47,1889"])
    if result_2 != 1202161486:
        raise Exception(f"Test 2.5 did not pass, got {result_2}")

    print("Tests passed")


if __name__ == "__main__":
    run_tests()

    input = read_inputs(13)

    result_1 = run_1(input)
    print(f"Finished 1 with result {result_1}")

    result_2 = run_2(input)
    print(f"Finished 2 with result {result_2}")
Пример #21
0
    if result_1 != 27:
        raise Exception(f"Test 1.4 did not past, got {result_1}")

    result_1 = run_1(["2,3,1"])
    if result_1 != 78:
        raise Exception(f"Test 1.5 did not past, got {result_1}")

    result_1 = run_1(["3,2,1"])
    if result_1 != 438:
        raise Exception(f"Test 1.6 did not past, got {result_1}")

    result_1 = run_1(["3,1,2"])
    if result_1 != 1836:
        raise Exception(f"Test 1.7 did not past, got {result_1}")

    # result_2 = run_2(test_inputs)
    # if result_2 != 0:
    #     raise Exception(f"Test 2 did not past, got {result_2}")


if __name__ == "__main__":
    run_tests()

    input = read_inputs(15)

    result_1 = run_1(input)
    print(f"Finished 1 with result {result_1}")

    result_2 = run_2(input)
    print(f"Finished 2 with result {result_2}")
Пример #22
0
    LLLL.LL.LL
    L.LL.LL.LL
    L.LLLLL.LL
    ..L.L.....
    LLLLLLLLLL
    L.LLLLLL.L
    L.LLLLL.LL
    """.strip().split('\n')

    result_1 = run_1(test_inputs)
    if result_1 != 37:
        raise Exception(f"Test 1 did not past, got {result_1}")
    print("Test 1 passed")

    result_2 = run_2(test_inputs)
    if result_2 != 26:
        raise Exception(f"Test 2 did not past, got {result_2}")
    print("Test 2 passed")


if __name__ == "__main__":
    run_tests()

    input = read_inputs(11)

    result_1 = run_1(input)
    print(f"Finished 1 with result {result_1}")

    result_2 = run_2(input)
    print(f"Finished 2 with result {result_2}")