def test(): input = [16,10,15,5,1,11,7,19,6,12,4] tmp = input[:] tmp.sort() assert part1(tmp) == 35 assert part2(tmp) == 8 print("Passed tests for", input) input = [28,33,18,42,31,14,46,20,48,47,24,23,49,45,19,38,39,11,1,32,25,35,8,17,7,9,4,2,34,10,3] tmp = input[:] tmp.sort() assert part1(tmp) == 220 assert part2(tmp) == 19208 print("Passed tests for", input)
def test(): vals_1 = read_file("test_input_1.txt") vals_2 = read_file("test_input_2.txt") vals_3 = read_file("test_input_3.txt") paths_1 = parse_paths(vals_1) paths_2 = parse_paths(vals_2) paths_3 = parse_paths(vals_3) assert part1(paths_1) == 10 assert part1(paths_2) == 19 assert part1(paths_3) == 226 print("Passed Part 1") assert part2(paths_1) == 36 assert part2(paths_2) == 103 assert part2(paths_3) == 3509 print("Passed Part 2")
def test(): vals = read_file("test_input.txt") assert part1(vals, days=18) == 26 assert part1(vals) == 5934 print("Passed Part 1") assert part2(vals) == 26984457539 print("Passed Part 2")
def test(): vals = read_file("test_input.txt") assert part1(vals) == 26 print("Passed Part 1") mapping_in = "acedgfb cdfbe gcdfa fbcad dab cefabd cdfgeb eafb cagedb ab".split( ) mapping = { "a": "d", "b": "e", "c": "a", "d": "f", "e": "g", "f": "b", "g": "c" } assert determine_mapping(mapping_in) == mapping print("Passed mapping test") decode_test_values = {"cdfeb": 5, "fcadb": 3, "cdfeb": 5, "cdbaf": 3} decode_mapping = {mapping[key]: key for key in mapping} assert all( determine_output(val, decode_mapping) == decode_test_values[val] for val in decode_test_values) print("Passed output test") assert part2(vals) == 61229 print("Passed Part 2")
def test(): input = [[".", "#", "."], [".", ".", "#"], ["#", "#", "#"]] data = parse_input(input) assert part1(data) == 112 print(f"Passed part 1") assert part2(data) == 848 print(f"Passed part 2")
def test(): vals = read_file("test_input.txt") vals = brute_force(vals) assert part1(vals) == 45 print("Passed Part 1") assert part2(vals) == 112 print("Passed Part 2")
def test(): vals = read_file("test_input_1.txt") assert part1(vals) == 40 print("Passed Part 1") assert expand(vals) == read_file("test_input_2.txt") print("Passed expansion") assert part2(vals) == 315 print("Passed Part 2")
def test(): vals = [ "00100", "11110", "10110", "10111", "10101", "01111", "00111", "11100", "10000", "11001", "00010", "01010" ] assert part1(vals) == 198 print("Passed Part 1") assert part2(vals) == 230 print("Passed Part 2")
def test(): vals = read_file("test_input.txt") octopuses = create_octopuses(vals) flashes = 0 for _ in range(10): flashes += step(octopuses) assert flashes == 204 print("Passed Test with 10 Iterations") assert part1(vals) == 1656 print("Passed Part 1") assert part2(vals) == 195 print("Passed Part 2")
def test(): input = (939, "7,13,x,x,59,x,31,19") timestamp = input[0] bus_ids = getDict(input[1]) assert part1(timestamp, bus_ids) == 295 assert part2(bus_ids) == 1068781 print(f"Passed test for ({input[0]}, [{input[1]}])") input = "17,x,13,19" bus_ids = getDict(input) assert part2(bus_ids) == 3417 print(f"Passed test for [{input}]") input = "67,7,59,61" bus_ids = getDict(input) assert part2(bus_ids) == 754018 print(f"Passed test for [{input}]") input = "67,x,7,59,61" bus_ids = getDict(input) assert part2(bus_ids) == 779210 print(f"Passed test for [{input}]") input = "67,7,x,59,61" bus_ids = getDict(input) assert part2(bus_ids) == 1261476 print(f"Passed test for [{input}]") input = "1789,37,47,1889" bus_ids = getDict(input) assert part2(bus_ids) == 1202161486 print(f"Passed test for [{input}]")
def test(): input = ["light red bags contain 1 bright white bag, 2 muted yellow bags.", "dark orange bags contain 3 bright white bags, 4 muted yellow bags.", "bright white bags contain 1 shiny gold bag.", "muted yellow bags contain 2 shiny gold bags, 9 faded blue bags.", "shiny gold bags contain 1 dark olive bag, 2 vibrant plum bags.", "dark olive bags contain 3 faded blue bags, 4 dotted black bags.", "vibrant plum bags contain 5 faded blue bags, 6 dotted black bags.", "faded blue bags contain no other bags.", "dotted black bags contain no other bags."] rules, amount = parseRules(input) assert part1(rules) == 4 assert part2(rules, amount) == 32 input = ["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."] rules, amount = parseRules(input) assert part2(rules, amount) == 126
def test(): assert part1([0, 3, 6]) == 436 assert part1([1, 3, 2]) == 1 assert part1([2, 1, 3]) == 10 assert part1([1, 2, 3]) == 27 assert part1([2, 3, 1]) == 78 assert part1([3, 2, 1]) == 438 assert part1([3, 1, 2]) == 1836 print(f"Passed part 1") assert part2([0,3,6]) == 175594 assert part2([1,3,2]) == 2578 assert part2([2,1,3]) == 3544142 assert part2([1,2,3]) == 261214 assert part2([2,3,1]) == 6895259 assert part2([3,2,1]) == 18 assert part2([3,1,2]) == 362 print(f"Passed part 2")
def test(): vals = read_file("test_input.txt") assert count(vals[0], vals[1], 1) == count_chars("NCNBCHB") assert count(vals[0], vals[1], 2) == count_chars("NBCCNBBBCBHCB") assert count(vals[0], vals[1], 3) == count_chars("NBBBCNCCNBBNBNBBCHBHHBCHB") assert count( vals[0], vals[1], 4) == count_chars("NBBNBNBBCCNBCNCCNBBNBBNBBBNBBNBBCBHCBHHNHCBBCBHCB") print("Passed Counting") elements = count(vals[0], vals[1], 10) assert elements == {"B": 1749, "C": 298, "H": 161, "N": 865} assert part1(*vals) == 1588 print("Passed Part 1") elements = count(vals[0], vals[1], 40) assert elements["B"] == 2192039569602 assert elements["H"] == 3849876073 assert part2(*vals) == 2188189693529 print("Passed Part 2")
def test(): assert decode_packet(hex2bin("D2FE28")) == (6, 4, 21, 2021) assert decode_packet(hex2bin("38006F45291200")) == (1, 6, 49, [(6, 4, 11, 10), (2, 4, 16, 20)]) assert decode_packet(hex2bin("EE00D40C823060")) == (7, 3, 51, [(2, 4, 11, 1), (4, 4, 11, 2), (1, 4, 11, 3)]) print("Passed decoding tests") assert part1("8A004A801A8002F478") == 16 assert part1("620080001611562C8802118E34") == 12 assert part1("C0015000016115A2E0802F182340") == 23 assert part1("A0016C880162017C3686B18A3D4780") == 31 print("Passed Part 1") assert part2("C200B40A82") == 3 assert part2("04005AC33890") == 54 assert part2("880086C3E88112") == 7 assert part2("CE00C43D881120") == 9 assert part2("D8005AC2A8F0") == 1 assert part2("F600BC2D8F") == 0 assert part2("9C005AC2F8F0") == 0 assert part2("9C0141080250320F1802104A08") == 1 print("Passed Part 2")
def test(): input = [['L', '.', 'L', 'L', '.', 'L', 'L', '.', 'L', 'L'], ['L', 'L', 'L', 'L', 'L', 'L', 'L', '.', 'L', 'L'], ['L', '.', 'L', '.', 'L', '.', '.', 'L', '.', '.'], ['L', 'L', 'L', 'L', '.', 'L', 'L', '.', 'L', 'L'], ['L', '.', 'L', 'L', '.', 'L', 'L', '.', 'L', 'L'], ['L', '.', 'L', 'L', 'L', 'L', 'L', '.', 'L', 'L'], ['.', '.', 'L', '.', 'L', '.', '.', '.', '.', '.'], ['L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L'], ['L', '.', 'L', 'L', 'L', 'L', 'L', 'L', '.', 'L'], ['L', '.', 'L', 'L', 'L', 'L', 'L', '.', 'L', 'L']] cache = create_cache(input) assert iterate( input, cache) == [['#', '.', '#', 'L', '.', 'L', '#', '.', '#', '#'], ['#', 'L', 'L', 'L', '#', 'L', 'L', '.', 'L', '#'], ['L', '.', '#', '.', 'L', '.', '.', '#', '.', '.'], ['#', 'L', '#', '#', '.', '#', '#', '.', 'L', '#'], ['#', '.', '#', 'L', '.', 'L', 'L', '.', 'L', 'L'], ['#', '.', '#', 'L', '#', 'L', '#', '.', '#', '#'], ['.', '.', 'L', '.', 'L', '.', '.', '.', '.', '.'], ['#', 'L', '#', 'L', '#', '#', 'L', '#', 'L', '#'], ['#', '.', 'L', 'L', 'L', 'L', 'L', 'L', '.', 'L'], ['#', '.', '#', 'L', '#', 'L', '#', '.', '#', '#']] assert iterate( input, cache, adjacent=False) == [['#', '.', 'L', '#', '.', 'L', '#', '.', 'L', '#'], ['#', 'L', 'L', 'L', 'L', 'L', 'L', '.', 'L', 'L'], ['L', '.', 'L', '.', 'L', '.', '.', '#', '.', '.'], ['#', '#', 'L', '#', '.', '#', 'L', '.', 'L', '#'], ['L', '.', 'L', '#', '.', 'L', 'L', '.', 'L', '#'], ['#', '.', 'L', 'L', 'L', 'L', '#', '.', 'L', 'L'], ['.', '.', '#', '.', 'L', '.', '.', '.', '.', '.'], ['L', 'L', 'L', '#', '#', '#', 'L', 'L', 'L', '#'], ['#', '.', 'L', 'L', 'L', 'L', 'L', '#', '.', 'L'], ['#', '.', 'L', '#', 'L', 'L', '#', '.', 'L', '#']] assert part1(input, cache) == 37 assert part2(input, cache) == 26 print("Passed tests for", input)
def test(): input = [["mask", "XXXXXXXXXXXXXXXXXXXXXXXXXXXXX1XXXX0X"], ["mem[8]", "11"], ["mem[7]", "101"], ["mem[8]", "0"]] assert run_v1(input) == {7: 101, 8: 64} assert part1(input) == 165 print(f"Passed part 1 for {input}") input = [["mask", "000000000000000000000000000000X1001X"], ["mem[42]", "100"], ["mask", "00000000000000000000000000000000X0XX"], ["mem[26]", "1"]] assert run_v2(input) == { 26: 1, 27: 1, 58: 100, 59: 100, 16: 1, 17: 1, 18: 1, 19: 1, 24: 1, 25: 1 } assert part2(input) == 208 print(f"Passed part 2 for {input}")
def test(): draws, fields = read_file("test_input.txt") assert part1(draws, fields) == 4512 print("Passed Part 1") assert part2(draws, fields) == 1924 print("Passed Part 2")
def test(): vals = [199, 200, 208, 210, 200, 207, 240, 269, 260, 263] assert part1(vals) == 7 print("Passed Part 1") assert part2(vals) == 5 print("Passed Part 2")
def test(): vals = read_file("test_input.txt") assert part1(vals) == 37 print("Passed Part 1") assert part2(vals) == 168 print("Passed Part 2")
def test(): input = [35, 20, 15, 25, 47, 40, 62, 55, 65, 95, 102, 117, 150, 182, 127, 219, 299, 277, 309, 579] assert part1(input, 5) == 127 assert part2(input, 127) == 62
def test(): instructions = [["nop", "+0"], ["acc", "+1"], ["jmp", "+4"], ["acc", "+3"], ["jmp", "-3"], ["acc", "-99"], ["acc", "+1"], ["jmp", "-4"], ["acc", "+6"]] assert (part1(instructions) == 5) assert part2(instructions) == 8
def test(): vals = read_file("test_input.txt") assert part1(vals) == 26397 print("Passed Part 1") assert part2(vals) == 288957 print("Passed Part 2")
def test(): vals = read_file("test_input.txt") assert part1(*vals) == 15 print("Passed Part 1") assert part2(*vals) == 1134 print("Passed Part 2")
def test(): input = ["F10", "N3", "F7", "R90", "F11"] assert part1(input) == 25 assert part2(input) == 286 print("Passed tests for", input)