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(): input = ['0: 1 2', '1: "a"', '2: 1 3 | 3 1', '3: "b"'] assert part1(parse_rules(input), ["aab", "aba"]) == 2 input = [ '0: 4 1 5', '1: 2 3 | 3 2', '2: 4 4 | 5 5', '3: 4 5 | 5 4', '4: "a"', '5: "b"' ] words = ["ababbb", "bababa", "abbbab", "aaabbb", "aaaabbb"] assert part1(parse_rules(input), words) == 2 print(f"Passed Part 1")
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(): 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(): 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(): 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") 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(): 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(): 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(): 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(): input = [[ "class: 1-3 or 5-7", "row: 6-11 or 33-44", "seat: 13-40 or 45-50" ], ["your ticket:", "7,1,14"], ["nearby tickets:", "7,3,47", "40,4,50", "55,2,20", "38,6,12"]] data = parseInput(input) assert part1(data) == 71 print(f"Passed part 1") input = [["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"]] data = parseInput(input) valid_tickets = get_valid_tickets(data) possible_positions = get_possible_positions(data["rules"], valid_tickets) positions = determine_positions(possible_positions) assert positions == {"row": 0, "class": 1, "seat": 2} assert data["you"][positions["class"]] == 12 assert data["you"][positions["row"]] == 11 assert data["you"][positions["seat"]] == 13 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(): 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 = ["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(): 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(): input = ["ecl:gry pid:860033327 eyr:2020 hcl:#fffffd","byr:1937 iyr:2017 cid:147 hgt:183cm", "","iyr:2013 ecl:amb cid:350 eyr:2023 pid:028048884","hcl:#cfa07d byr:1929","", "hcl:#ae17e1 iyr:2013","eyr:2024","ecl:brn pid:760753108 byr:1931", "hgt:179cm", "", "hcl:#cfa07d eyr:2025 pid:166559648", "iyr:2011 ecl:brn hgt:59in"] passports = parse_data(input) assert len(passports) == 4 assert part1(passports) == 2 input = ["eyr:1972 cid:100","hcl:#18171d ecl:amb hgt:170 pid:186cm iyr:2018 byr:1926","", "iyr:2019","hcl:#602927 eyr:1967 hgt:170cm","ecl:grn pid:012533040 byr:1946","", "hcl:dab227 iyr:2012","ecl:brn hgt:182cm pid:021572410 eyr:2020 byr:1992 cid:277","", "hgt:59cm ecl:zzz","eyr:2038 hcl:74454a iyr:2023","pid:3556412378 byr:2007"] passports = parse_data(input) assert all((not p.valid_data() for p in passports)) input = ["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"] passports = parse_data(input) assert all((p.valid_data() for p in passports)) assert passport.validate_byr(2002) == True assert passport.validate_byr(2003) == False assert passport.validate_hgt("60in") == True assert passport.validate_hgt("190cm") == True assert passport.validate_hgt("190in") == False assert passport.validate_hgt("190") == False assert passport.validate_hcl("#123abc") == True assert passport.validate_hcl("#123abz") == False assert passport.validate_hcl("123abc") == False assert passport.validate_ecl("brn") == True assert passport.validate_ecl("wat") == False assert passport.validate_pid("000000001") == True assert passport.validate_pid("0123456789") == False
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(): 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(): 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(): vals = read_file("test_input.txt") assert part1(vals) == 37 print("Passed Part 1") assert part2(vals) == 168 print("Passed Part 2")
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)