def test_solve_one_1(): input = """ 0,3,6 """.strip().replace(' ', '') starting_numbers = parse_input(input) result = solve_one(starting_numbers, 2020) assert result == 436
def test_solve_two_6(): input = """ 2,3,1 """.strip().replace(' ', '') starting_numbers = parse_input(input) result = solve_two(starting_numbers, 30000000) assert result == 6895259
def test_solve_two_1(): input = """ 0,3,6 """.strip().replace(' ', '') starting_numbers = parse_input(input) result = solve_two(starting_numbers, 30000000) assert result == 175594
def test_solve_one_8(): input = """ 3,1,2 """.strip().replace(' ', '') starting_numbers = parse_input(input) result = solve_one(starting_numbers, 2020) assert result == 1836
def travel_plan(): input = """ 939 7,13,x,x,59,x,31,19 """.strip().replace(' ', '') travel_plan = parse_input(input) return travel_plan
def test_solve_two_3(): input = """ 2,1,3 """.strip().replace(' ', '') starting_numbers = parse_input(input) result = solve_two(starting_numbers, 30000000) assert result == 3544142
def test_solve_two_4(): input = """ 1,2,3 """.strip().replace(' ', '') starting_numbers = parse_input(input) result = solve_two(starting_numbers, 30000000) assert result == 261214
def test_parse_input(self): parsed = parse_input([ 'C - 3 - 4', 'M - 2 - 1', 'T - 1 - 2 - 3', 'A - Lara - 1 - 1 - N - AADA' ]) result = { 'C': [{ 1: '3', 2: '4' }], 'M': [{ 1: '2', 2: '1' }], 'T': [{ 1: '1', 2: '2', 3: '3' }], 'A': [{ 1: 'Lara', 2: '1', 3: '1', 4: 'N', 5: 'AADA' }] } self.assertEqual(parsed, result, "Should be 6")
def transmission(): input = """ 35 20 15 25 47 40 62 55 65 95 102 117 150 182 127 219 299 277 309 576 """.strip().replace(' ', '') transmission = parse_input(input) return transmission
def initial_state(): input = """ .#. ..# ### """.strip().replace(' ', '') initial_state = parse_input(input) return initial_state
def instructions_one(): input = """ mask = XXXXXXXXXXXXXXXXXXXXXXXXXXXXX1XXXX0X mem[8] = 11 mem[7] = 101 mem[8] = 0 """.strip().replace(' ', '') instructions = parse_input(input) return instructions
def instructions_two(): input = """ mask = 000000000000000000000000000000X1001X mem[42] = 100 mask = 00000000000000000000000000000000X0XX mem[26] = 1 """.strip().replace(' ', '') instructions = parse_input(input) return instructions
def instructions(): input = """ F10 N3 F7 R90 F11 """.strip().replace(' ', '') instructions = parse_input(input) return instructions
def seat_layout(): input = """ L.LL.LL.LL LLLLLLL.LL L.L.L..L.. LLLL.LL.LL L.LL.LL.LL L.LLLLL.LL ..L.L..... LLLLLLLLLL L.LLLLLL.L L.LLLLL.LL """.strip().replace(' ', '') seat_layout = parse_input(input) return seat_layout
def ticket_details_two(): 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 """.strip().replace(' ', '') requirements, personal_ticket, other_tickets = parse_input(input) return requirements, personal_ticket, other_tickets
def test_step_moons(): input = """<x=-1, y=0, z=2> <x=2, y=-10, z=-7> <x=4, y=-8, z=8> <x=3, y=5, z=-1>""" moons = parse_input(input) step(moons) assert moons[0].position == [2, -1, 1] assert moons[1].position == [3, -7, -4] assert moons[2].position == [1, -7, 5] assert moons[3].position == [2, 2, 0] assert moons[0].velocity == [3, -1, -1] assert moons[1].velocity == [1, 3, 3] assert moons[2].velocity == [-3, 1, -3] assert moons[3].velocity == [-1, -3, 1]
def adapters(): input = """ 16 10 15 5 1 11 7 19 6 12 4 """.strip().replace(' ', '') adapters = parse_input(input) return adapters
def valid_passports(): passport_text = """ 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().replace(' ', '') passports = parse_input(passport_text) return passports
def ticket_details_one(): 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 """.strip().replace(' ', '') requirements, personal_ticket, other_tickets = parse_input(input) return requirements, personal_ticket, other_tickets
def invalid_passports(): passport_text = """ 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 """.strip().replace(' ', '') passports = parse_input(passport_text) return passports
def passports(): passport_text = """ 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 """.strip().replace(' ', '') passports = parse_input(passport_text) return passports
def test_step_10x_moons(): input = """<x=-1, y=0, z=2> <x=2, y=-10, z=-7> <x=4, y=-8, z=8> <x=3, y=5, z=-1>""" moons = parse_input(input) r = simulate_moons(moons, 10) assert moons[0].position == [2, 1, -3] assert moons[1].position == [1, -8, 0] assert moons[2].position == [3, -6, 1] assert moons[3].position == [2, 0, 4] assert moons[0].velocity == [-3, -2, 1] assert moons[1].velocity == [-1, 1, 3] assert moons[2].velocity == [3, 2, -3] assert moons[3].velocity == [1, -1, -1] assert r == 179
def larger_adapters(): 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 """.strip().replace(' ', '') adapters = parse_input(input) return adapters
def test_solve_two_alt_five(): schedules = parse_input(""" 0 1789,37,47,1889 """.strip().replace(' ', ''))[1] assert solve_two(schedules) == 1202161486
def testOneInvalidArgument(self): tokens = ['foobar'] data, language = main.parse_input(tokens) self.assertEqual({}, data) self.assertIsNone(language)
def test_solve_two_alt_four(): schedules = parse_input(""" 0 67,7,x,59,61 """.strip().replace(' ', ''))[1] assert solve_two(schedules) == 1261476
def testValidArgumentsFr(self): tokens = ['de', 'Zürich', 'à', 'Locarno', 'via', 'Genève', 'départ', '18:00', 'arrivée', '19:00'] data, language = main.parse_input(tokens, sloppy_validation=True) self.assertEqual(self.valid_expected_result, data) self.assertEqual('fr', language)
def test_floor_processor(self): floor, firstBasementFloor = main.parse_input(')))') self.assertEqual(firstBasementFloor, 1) self.assertEqual(floor, -3)
def testEmptyArguments(self): tokens = [] data, language = main.parse_input(tokens) self.assertEqual({}, data) self.assertIsNone(language)
def test_parse_input(self): self.assertEqual(main.parse_input("111 2 3333\n4 5 6"), [[111, 2, 3333], [4, 5, 6]])
def testValidArgumentsDe(self): tokens = ['von', 'Zürich', 'nach', 'Locarno', 'via', 'Genève', 'ab', '18:00', 'an', '19:00'] data, language = main.parse_input(tokens, sloppy_validation=True) self.assertEqual(self.valid_expected_result, data) self.assertEqual('de', language)
def main(): initial_state, step_count, states = parse_input("input") generate_c(initial_state, step_count, states)
def test_parse_input(input_string, expected_output): assert parse_input(input_string) == expected_output
def test_solve_two_alt_three(): schedules = parse_input(""" 0 67,x,7,59,61 """.strip().replace(' ', ''))[1] assert solve_two(schedules) == 779210