Пример #1
0
def is_valid(policy_and_pass_string):
    pos1_pos2_letter_pass = parse_policy_and_pass(policy_and_pass_string)
    assert_with_message(4, len(pos1_pos2_letter_pass))
    letter = pos1_pos2_letter_pass[2]
    password = pos1_pos2_letter_pass[3]
    found_at_pos1 = password[pos1_pos2_letter_pass[0]] == letter
    found_at_pos2 = password[pos1_pos2_letter_pass[1]] == letter
    return found_at_pos1 ^ found_at_pos2
Пример #2
0
 def test_today(self):
     test_input = [
         'nop +0', 'acc +1', 'jmp +4', 'acc +3', 'jmp -3', 'acc -99',
         'acc +1', 'jmp -4', 'acc +6'
     ]
     assert_with_message(5, get_final_acc(test_input))
     assert_with_message(1818, get_final_acc(get_input(8)))
     run()
Пример #3
0
 def test_part2(self):
     test1_input = ['1-3 a: abcde', '1-3 b: cdefg', '2-9 c: ccccccccc']
     assert_with_message(4, len(parse_policy_and_pass(test1_input[0])))
     assert_with_message(0, parse_policy_and_pass(test1_input[0])[0])
     assert_with_message(2, parse_policy_and_pass(test1_input[0])[1])
     assert_with_message('a', parse_policy_and_pass(test1_input[0])[2])
     assert_with_message('abcde', parse_policy_and_pass(test1_input[0])[3])
     assert is_valid(test1_input[0])
     assert not is_valid(test1_input[1])
     assert not is_valid(test1_input[2])
     part1()
Пример #4
0
 def test_part1(self):
     test_input = ['..##.......',
                   '#...#...#..',
                   '.#....#..#.',
                   '..#.#...#.#',
                   '.#...##..#.',
                   '..#.##.....',
                   '.#.#.#....#',
                   '.#........#',
                   '#.##...#...',
                   '#...##....#',
                   '.#..#...#.#']
     assert_with_message(7, count_trees(test_input, 3))
     part1()
Пример #5
0
 def test_part(self):
     given_input1 = ['939', '7,13,x,x,59,x,31,19']
     assert_with_message([939, [7, 13, 59, 31, 19]],
                         process_input(given_input1))
     assert_with_message(295, get_soonest_bus_times_wait(given_input1))
     assert_with_message(104, get_soonest_bus_times_wait(get_input(13)))
     run()
Пример #6
0
    def test_part(self):
        test_input1 = input_strings_to_ints(
            ['16', '10', '15', '5', '1', '11', '7', '19', '6', '12', '4'])
        test_input2 = input_strings_to_ints([
            '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'
        ])
        day_input = get_input(10)
        if day_input[len(day_input) - 1] == '':
            day_input = day_input[:len(day_input) - 1]
        day_input = input_strings_to_ints(day_input)
        test_input1.sort()
        assert_with_message(8, get_num_configs_recursively([0] + test_input1))
        test_input2.sort()
        assert_with_message(19208,
                            get_num_configs_recursively([0] + test_input2))

        assert_with_message(8, get_num_configs([0] + test_input1))
        assert_with_message(19208, get_num_configs([0] + test_input2))
        assert_with_message(173625106649344, get_num_configs([0] + day_input))
        run()
Пример #7
0
 def test_part1(self):
     test_input = [
         'abc', '', 'a', 'b', 'c', '', 'ab', 'ac', '', 'a', 'a', 'a', 'a',
         '', 'b'
     ]
     assert_with_message(11, get_total(test_input))
     assert_with_message(6714, get_total(get_lines('day6.input')))
     assert_with_message(6714, get_total(get_input(6)))
     part1()
Пример #8
0
 def test_part1(self):
     test_input = [
         'abc', '', 'a', 'b', 'c', '', 'ab', 'ac', '', 'a', 'a', 'a', 'a',
         '', 'b', ''
     ]
     assert_with_message(6, get_total(test_input))
     assert_with_message(3435, get_total(get_lines('day6.input') + ['']))
     assert_with_message(3435, get_total(get_input(6)))
     part2()
Пример #9
0
 def test_part1(self):
     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'
     ]
     assert parse_entry_line(test_input[0]) == ['ecl', 'pid', 'eyr', 'hcl']
     assert parse_entry_line(test_input[1]) == ['byr', 'iyr', 'cid', 'hgt']
     assert parse_entry_line(test_input[2]) is None
     assert_with_message(['eyr'], parse_entry_line(test_input[7]))
     assert_with_message(4, len(parse_passport_entries(test_input)))
     assert parse_passport_entries(test_input)[0] == [
         'ecl', 'pid', 'eyr', 'hcl', 'byr', 'iyr', 'cid', 'hgt'
     ]
     assert parse_passport_entries(test_input)[1] == [
         'iyr', 'ecl', 'cid', 'eyr', 'pid', 'hcl', 'byr'
     ]
     assert parse_passport_entries(test_input)[2] == [
         'hcl', 'iyr', 'eyr', 'ecl', 'pid', 'byr', 'hgt'
     ]
     assert parse_passport_entries(test_input)[3] == [
         'hcl', 'eyr', 'pid', 'iyr', 'ecl', 'hgt'
     ]
     assert passport_is_valid(
         ['ecl', 'pid', 'eyr', 'hcl', 'byr', 'iyr', 'cid', 'hgt'])
     assert not passport_is_valid(
         ['iyr', 'ecl', 'cid', 'eyr', 'pid', 'hcl', 'byr'])
     assert passport_is_valid(
         ['hcl', 'iyr', 'eyr', 'ecl', 'pid', 'byr', 'hgt'])
     assert not passport_is_valid(
         ['hcl', 'eyr', 'pid', 'iyr', 'ecl', 'hgt'])
     assert find_number_of_valid_passports(test_input) == 2
     part1()
Пример #10
0
 def test_part2(self):
     test_input = [
         '..##.......', '#...#...#..', '.#....#..#.', '..#.#...#.#',
         '.#...##..#.', '..#.##.....', '.#.#.#....#', '.#........#',
         '#.##...#...', '#...##....#', '.#..#...#.#'
     ]
     assert_with_message(7, count_trees(test_input, 3))
     assert_with_message(336, combine_paths(test_input))
     map_lines = get_lines('day3.input')
     assert_with_message(211, count_trees(map_lines, 3))
     part2()
Пример #11
0
 def test_part(self):
     test_input1 = input_strings_to_ints(
         ['16', '10', '15', '5', '1', '11', '7', '19', '6', '12', '4'])
     assert_with_message([7, 5], get_num_1_and_3_joltage_gaps(test_input1))
     test_input2 = input_strings_to_ints([
         '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'
     ])
     assert_with_message([22, 10],
                         get_num_1_and_3_joltage_gaps(test_input2))
     day_input = get_input(10)
     if day_input[len(day_input) - 1] == '':
         day_input = day_input[:len(day_input) - 1]
     day_input = input_strings_to_ints(day_input)
     assert_with_message([72, 31], get_num_1_and_3_joltage_gaps(day_input))
     assert_with_message(2232,
                         get_num_1_and_3_joltage_gap_product(day_input))
     run()
Пример #12
0
 def test_part2(self):
     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'
     ]
     assert_with_message(
         {
             'ecl': 'gry',
             'pid': '860033327',
             'eyr': '2020',
             'hcl': '#fffffd'
         }, parse_entry_line(test_input[0]))
     assert parse_entry_line(test_input[1]) == {
         'byr': '1937',
         'iyr': '2017',
         'cid': '147',
         'hgt': '183cm'
     }
     assert parse_entry_line(test_input[2]) is None
     assert_with_message({'eyr': '2024'}, parse_entry_line(test_input[7]))
     assert_with_message(4, len(parse_passport_entries(test_input)))
     assert parse_passport_entries(test_input)[0] == {
         'ecl': 'gry',
         'pid': '860033327',
         'eyr': '2020',
         'hcl': '#fffffd',
         'byr': '1937',
         'iyr': '2017',
         'cid': '147',
         'hgt': '183cm'
     }
     assert parse_passport_entries(test_input)[3] == {
         'hcl': '#cfa07d',
         'eyr': '2025',
         'pid': '166559648',
         'iyr': '2011',
         'ecl': 'brn',
         'hgt': '59in'
     }
     assert passport_is_valid({
         'ecl': 'gry',
         'pid': '860033327',
         'eyr': '2020',
         'hcl': '#fffffd',
         'byr': '1937',
         'iyr': '2017',
         'cid': '147',
         'hgt': '183cm'
     })
     assert not passport_is_valid({
         'ecl': 'gry',
         'pid': '860033327',
         'eyr': '2020',
         'hcl': '#fffffd',
         'byr': '1919',
         'iyr': '2017',
         'cid': '147',
         'hgt': '183cm'
     })
     assert not passport_is_valid({
         'ecl': 'gry',
         'pid': '860033327',
         'eyr': '2020',
         'hcl': '#fffffd',
         'byr': '2003',
         'iyr': '2017',
         'cid': '147',
         'hgt': '183cm'
     })
     assert not passport_is_valid({
         'ecl': 'gry',
         'pid': '860033327',
         'eyr': '2020',
         'hcl': '#fffffd',
         'byr': '1937',
         'iyr': '2009',
         'cid': '147',
         'hgt': '183cm'
     })
     assert not passport_is_valid({
         'ecl': 'gry',
         'pid': '860033327',
         'eyr': '2020',
         'hcl': '#fffffd',
         'byr': '1937',
         'iyr': '2021',
         'cid': '147',
         'hgt': '183cm'
     })
     assert not passport_is_valid({
         'ecl': 'gry',
         'pid': '860033327',
         'eyr': '2019',
         'hcl': '#fffffd',
         'byr': '1937',
         'iyr': '2017',
         'cid': '147',
         'hgt': '183cm'
     })
     assert not passport_is_valid({
         'ecl': 'gry',
         'pid': '860033327',
         'eyr': '2031',
         'hcl': '#fffffd',
         'byr': '1937',
         'iyr': '2017',
         'cid': '147',
         'hgt': '183cm'
     })
     assert not passport_is_valid({
         'ecl': 'gry',
         'pid': '860033327',
         'eyr': '2020',
         'hcl': '#fffffd',
         'byr': '1937',
         'iyr': '2017',
         'cid': '147',
         'hgt': '149cm'
     })
     assert not passport_is_valid({
         'ecl': 'gry',
         'pid': '860033327',
         'eyr': '2020',
         'hcl': '#fffffd',
         'byr': '1937',
         'iyr': '2017',
         'cid': '147',
         'hgt': '194cm'
     })
     assert not passport_is_valid({
         'ecl': 'gry',
         'pid': '860033327',
         'eyr': '2020',
         'hcl': '#fffffd',
         'byr': '1937',
         'iyr': '2017',
         'cid': '147',
         'hgt': '58in'
     })
     assert not passport_is_valid({
         'ecl': 'gry',
         'pid': '860033327',
         'eyr': '2020',
         'hcl': '#fffffd',
         'byr': '1937',
         'iyr': '2017',
         'cid': '147',
         'hgt': '77in'
     })
     assert not passport_is_valid({
         'ecl': 'gry',
         'pid': '860033327',
         'eyr': '2020',
         'hcl': '#wffffd',
         'byr': '1937',
         'iyr': '2017',
         'cid': '147',
         'hgt': '183cm'
     })
     assert not passport_is_valid({
         'ecl': 'gry',
         'pid': '860033327',
         'eyr': '2020',
         'hcl': '#fffffdd',
         'byr': '1937',
         'iyr': '2017',
         'cid': '147',
         'hgt': '183cm'
     })
     assert not passport_is_valid({
         'ecl': 'yel',
         'pid': '860033327',
         'eyr': '2020',
         'hcl': '#fffffd',
         'byr': '1937',
         'iyr': '2017',
         'cid': '147',
         'hgt': '183cm'
     })
     assert not passport_is_valid({
         'ecl': 'gry',
         'pid': '0860033327',
         'eyr': '2020',
         'hcl': '#fffffd',
         'byr': '1937',
         'iyr': '2017',
         'cid': '147',
         'hgt': '183cm'
     })
     assert not passport_is_valid({
         'ecl': 'gry',
         'pid': '0033327',
         'eyr': '2020',
         'hcl': '#fffffd',
         'byr': '1937',
         'iyr': '2017',
         'cid': '147',
         'hgt': '183cm'
     })
     assert find_number_of_valid_passports(test_input) == 2
     invalid = [
         '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'
     ]
     assert find_number_of_valid_passports(invalid) == 0
     valid = [
         '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'
     ]
     assert find_number_of_valid_passports(valid) == 4
     part2()
Пример #13
0
    def test_part(self):
        assert_with_message([11, 12],
                            get_consecutive_schedule_with_minimum([11, 0],
                                                                  [4, 1],
                                                                  [10, 10]))
        assert_with_message([15, 16],
                            get_consecutive_schedule_with_minimum([5, 0],
                                                                  [4, 1],
                                                                  [10, 10]))
        assert_with_message([8, 10],
                            get_consecutive_schedule_with_minimum([2, 0],
                                                                  [5, 2],
                                                                  [0, 0]))
        assert_with_message([18, 20],
                            get_consecutive_schedule_with_minimum([2, 0],
                                                                  [5, 2],
                                                                  [10, 10]))

        given_input1 = ['939', '7,13,x,x,59,x,31,19']
        processed_given_input1 = process_input(given_input1)
        assert_with_message([[7, 0], [13, 1], [59, 4], [31, 6], [19, 7]],
                            processed_given_input1)

        assert_with_message(2, find_consecutive_schedule([[2, 0], [3, 1]]))

        assert_with_message(11, find_consecutive_schedule([[11, 0], [4, 1]]))
        assert_with_message(15, find_consecutive_schedule([[5, 0], [4, 1]]))
        assert_with_message(8, find_consecutive_schedule([[2, 0], [5, 2]]))
        assert_with_message(
            14, find_consecutive_schedule([[7, 0], [5, 1], [4, 2]]))
        assert_with_message(
            1, find_consecutive_schedule([[1, 0], [2, 1], [3, 2]]))
        assert_with_message(
            12, find_consecutive_schedule([[2, 0], [5, 3], [6, 6]]))
        assert_with_message(
            20, find_consecutive_schedule([[5, 0], [7, 1], [11, 2]]))
        assert_with_message(
            2, find_consecutive_schedule([[2, 0], [2, 2], [2, 4]]))

        test_input1 = process_input(given_input1)
        assert_with_message(1068781, find_consecutive_schedule(test_input1))
        test_input2 = process_input(['', '17,x,13,19'])
        assert_with_message(3417, find_consecutive_schedule(test_input2))
        test_input3 = process_input(['', '67,7,59,61'])
        assert_with_message(754018, find_consecutive_schedule(test_input3))
        test_input4 = process_input(['', '67,x,7,59,61'])
        assert_with_message(779210, find_consecutive_schedule(test_input4))
        test_input5 = process_input(['', '67,7,x,59,61'])
        assert_with_message(1261476, find_consecutive_schedule(test_input5))
        test_input5 = process_input(['', '1789,37,47,1889'])
        assert_with_message(1202161486, find_consecutive_schedule(test_input5))

        day_input = process_input(get_input(13))
        assert_with_message(1202161486, find_consecutive_schedule(day_input))

        run()
Пример #14
0
    def test_today(self):
        test_line = 'light red bags contain 1 bright white bag, 2 muted yellow bags.'
        test_line_with_none = 'dotted black bags contain no other bags.'
        assert_with_message(
            'light red bag contain 1 bright white bag 2 muted yellow bag',
            pre_process_rule(test_line))
        assert_with_message('dotted black bag contain no other bag',
                            pre_process_rule(test_line_with_none))
        assert_with_message('light red', get_containing_bag(test_line))
        assert_with_message({
            'bright white': 1,
            'muted yellow': 2
        }, get_contained_bags(test_line))
        assert_with_message(None, get_contained_bags(test_line_with_none))
        assert_with_message(
            {
                'light red': {
                    'bright white': 1,
                    'muted yellow': 2
                },
                'dotted black': None
            },
            get_containing_to_contained_bags_map(
                [test_line, test_line_with_none]))
        containing_to_contained_bags_map = get_containing_to_contained_bags_map(
            [test_line, test_line_with_none])
        assert_with_message(
            True,
            can_contain_bag('bright white', 'light red',
                            containing_to_contained_bags_map))
        assert_with_message(
            False,
            can_contain_bag('vibrant plum', 'light red',
                            containing_to_contained_bags_map))
        assert_with_message(
            False,
            can_contain_bag('bright white', 'dotted black',
                            containing_to_contained_bags_map))

        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.'
        ]
        assert_with_message(4, get_num_containing_bags('shiny gold',
                                                       test_input))
        assert_with_message(
            235, get_num_containing_bags('shiny gold', get_input(7)))
        run()
Пример #15
0
def is_valid(policy_and_pass_string):
    min_max_letter_pass = parse_policy_and_pass(policy_and_pass_string)
    assert_with_message(4, len(min_max_letter_pass))
    counter = Counter(min_max_letter_pass[3])
    count = counter[min_max_letter_pass[2]]
    return min_max_letter_pass[0] <= count <= min_max_letter_pass[1]
Пример #16
0
def assert_row_column_seatid(code: str, row, column, seat_id):
    assert_with_message(row, calculate_row(code))
    assert_with_message(column, calculate_column(code))
    assert_with_message(seat_id, calculate_seat_id(code))
Пример #17
0
 def test_part(self):
     test_ship = [0, 0]
     test_waypoint = [10, 1]
     test_start = [test_ship, test_waypoint]
     assert_with_message([test_ship, [10, 2]],
                         process_instruction(copy.deepcopy(test_start),
                                             'N1'))
     assert_with_message([test_ship, [12, 1]],
                         process_instruction(copy.deepcopy(test_start),
                                             'E2'))
     assert_with_message([test_ship, [10, -2]],
                         process_instruction(copy.deepcopy(test_start),
                                             'S3'))
     assert_with_message([test_ship, [6, 1]],
                         process_instruction(copy.deepcopy(test_start),
                                             'W4'))
     assert_with_message([[50, 5], test_waypoint],
                         process_instruction(copy.deepcopy(test_start),
                                             'F5'))
     assert_with_message([test_ship, [1, -10]],
                         process_instruction(copy.deepcopy(test_start),
                                             'R90'))
     assert_with_message([test_ship, [-10, -1]],
                         process_instruction(copy.deepcopy(test_start),
                                             'L180'))
     assert_with_message([test_ship, [-1, 10]],
                         process_instruction(copy.deepcopy(test_start),
                                             'R270'))
     assert_with_message([test_ship, [10, 1]],
                         process_instruction(copy.deepcopy(test_start),
                                             'L360'))
     given_input1 = ['F10', 'N3', 'F7', 'R90', 'F11']
     assert_with_message(286, navigate_and_get_hattie_dist(given_input1))
     assert_with_message(52866, navigate_and_get_hattie_dist(get_input(12)))
     run()
Пример #18
0
 def test_today(self):
     assert_with_message(True, is_sum_of_previous(13,
                                                  [1, 2, 3, 10, 14, 15]))
     assert_with_message(True, is_sum_of_previous(16, [1, 2, 3, 4, 14, 15]))
     assert_with_message(10, find_not_sum([1, 2, 3, 10, 14, 15], 3))
     assert_with_message(14, find_not_sum([1, 2, 3, 4, 14, 15], 3))
     test_input = input_strings_to_ints([
         '35', '20', '15', '25', '47', '40', '62', '55', '65', '95', '102',
         '117', '150', '182', '127', '219', '299', '277', '309', '576'
     ])
     assert_with_message(127, find_not_sum(test_input, 5))
     day_input_string = get_input(9)
     day_input = input_strings_to_ints(
         day_input_string[:len(day_input_string) - 1])
     assert_with_message(29221323, find_not_sum(day_input, 25))
     run()
Пример #19
0
    def test_part(self):
        test_input1 = ['L#L', '#L#', 'L#L']
        test_input2 = ['#L#', 'L#L', '#L#']
        assert_with_message(2,
                            count_occupied_adjacent_seats(0, 0, test_input1))
        assert_with_message(2,
                            count_occupied_adjacent_seats(0, 1, test_input1))
        assert_with_message(2,
                            count_occupied_adjacent_seats(0, 2, test_input1))
        assert_with_message(2,
                            count_occupied_adjacent_seats(1, 0, test_input1))
        assert_with_message(4,
                            count_occupied_adjacent_seats(1, 1, test_input1))
        assert_with_message(2,
                            count_occupied_adjacent_seats(1, 2, test_input1))
        assert_with_message(2,
                            count_occupied_adjacent_seats(2, 0, test_input1))
        assert_with_message(2,
                            count_occupied_adjacent_seats(2, 1, test_input1))
        assert_with_message(2,
                            count_occupied_adjacent_seats(2, 2, test_input1))
        assert_with_message(1,
                            count_occupied_adjacent_seats(0, 0, test_input2))
        assert_with_message(3,
                            count_occupied_adjacent_seats(0, 1, test_input2))
        assert_with_message(1,
                            count_occupied_adjacent_seats(0, 2, test_input2))
        assert_with_message(3,
                            count_occupied_adjacent_seats(1, 0, test_input2))
        assert_with_message(4,
                            count_occupied_adjacent_seats(1, 1, test_input2))
        assert_with_message(3,
                            count_occupied_adjacent_seats(1, 2, test_input2))
        assert_with_message(1,
                            count_occupied_adjacent_seats(2, 0, test_input2))
        assert_with_message(3,
                            count_occupied_adjacent_seats(2, 1, test_input2))
        assert_with_message(1,
                            count_occupied_adjacent_seats(2, 2, test_input2))
        expected_result1 = ['#L#', 'LLL', '#L#']
        assert_with_message(expected_result1,
                            update_seats(['###', '###', '###']))
        expected_result2 = ['.##', '#.#', '##.']
        assert_with_message(expected_result2,
                            update_seats(['.LL', 'L.L', 'LL.']))
        given_input1 = [
            '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'
        ]
        given_input2 = [
            '#.##.##.##', '#######.##', '#.#.#..#..', '####.##.##',
            '#.##.##.##', '#.#####.##', '..#.#.....', '##########',
            '#.######.#', '#.#####.##'
        ]
        assert_with_message(given_input2, update_seats(given_input1))
        given_input3 = [
            '#.LL.L#.##', '#LLLLLL.L#', 'L.L.L..L..', '#LLL.LL.L#',
            '#.LL.LL.LL', '#.LLLL#.##', '..L.L.....', '#LLLLLLLL#',
            '#.LLLLLL.L', '#.#LLLL.##'
        ]
        assert_with_message(given_input3, update_seats(given_input2))
        given_input4 = [
            '#.##.L#.##', '#L###LL.L#', 'L.#.#..#..', '#L##.##.L#',
            '#.##.LL.LL', '#.###L#.##', '..#.#.....', '#L######L#',
            '#.LL###L.L', '#.#L###.##'
        ]
        assert_with_message(given_input4, update_seats(given_input3))
        given_input5 = [
            '#.#L.L#.##', '#LLL#LL.L#', 'L.L.L..#..', '#LLL.##.L#',
            '#.LL.LL.LL', '#.LL#L#.##', '..L.L.....', '#L#LLLL#L#',
            '#.LLLLLL.L', '#.#L#L#.##'
        ]
        assert_with_message(given_input5, update_seats(given_input4))
        given_input6 = [
            '#.#L.L#.##', '#LLL#LL.L#', 'L.#.L..#..', '#L##.##.L#',
            '#.#L.LL.LL', '#.#L#L#.##', '..L.L.....', '#L#L##L#L#',
            '#.LLLLLL.L', '#.#L#L#.##'
        ]
        assert_with_message(given_input6, update_seats(given_input5))
        assert_with_message(37, get_num_occupied_after_updates(given_input1))
        assert_with_message(2418,
                            get_num_occupied_after_updates(get_input(11)))

        run()
Пример #20
0
    def test_today(self):
        test_line = 'light red bags contain 1 bright white bag, 2 muted yellow bags.'
        test_line_with_none = 'dotted black bags contain no other bags.'
        assert_with_message(
            'light red bag contain 1 bright white bag 2 muted yellow bag',
            pre_process_rule(test_line))
        assert_with_message('dotted black bag contain no other bag',
                            pre_process_rule(test_line_with_none))
        assert_with_message('light red', get_containing_bag(test_line))
        assert_with_message({
            'bright white': 1,
            'muted yellow': 2
        }, get_contained_bags(test_line))
        assert_with_message(None, get_contained_bags(test_line_with_none))
        assert_with_message(
            {
                'light red': {
                    'bright white': 1,
                    'muted yellow': 2
                },
                'dotted black': None
            },
            get_containing_to_contained_bags_map(
                [test_line, test_line_with_none]))

        test_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.'
        ]
        assert_with_message(
            126,
            get_num_contained_bags(
                'shiny gold',
                get_containing_to_contained_bags_map(test_input)))
        assert_with_message(
            158493,
            get_num_contained_bags(
                'shiny gold',
                get_containing_to_contained_bags_map(get_input(7))))
        run()
Пример #21
0
    def test_part(self):
        test_input1 = ['L#L', '#L#', 'L#L']
        test_input2 = ['#L#', 'L#L', '#L#']
        assert_with_message(
            2, count_occupied_seats_in_all_directions(0, 0, test_input1))
        assert_with_message(
            2, count_occupied_seats_in_all_directions(0, 1, test_input1))
        assert_with_message(
            2, count_occupied_seats_in_all_directions(0, 2, test_input1))
        assert_with_message(
            2, count_occupied_seats_in_all_directions(1, 0, test_input1))
        assert_with_message(
            4, count_occupied_seats_in_all_directions(1, 1, test_input1))
        assert_with_message(
            2, count_occupied_seats_in_all_directions(1, 2, test_input1))
        assert_with_message(
            2, count_occupied_seats_in_all_directions(2, 0, test_input1))
        assert_with_message(
            2, count_occupied_seats_in_all_directions(2, 1, test_input1))
        assert_with_message(
            2, count_occupied_seats_in_all_directions(2, 2, test_input1))
        assert_with_message(
            1, count_occupied_seats_in_all_directions(0, 0, test_input2))
        assert_with_message(
            3, count_occupied_seats_in_all_directions(0, 1, test_input2))
        assert_with_message(
            1, count_occupied_seats_in_all_directions(0, 2, test_input2))
        assert_with_message(
            3, count_occupied_seats_in_all_directions(1, 0, test_input2))
        assert_with_message(
            4, count_occupied_seats_in_all_directions(1, 1, test_input2))
        assert_with_message(
            3, count_occupied_seats_in_all_directions(1, 2, test_input2))
        assert_with_message(
            1, count_occupied_seats_in_all_directions(2, 0, test_input2))
        assert_with_message(
            3, count_occupied_seats_in_all_directions(2, 1, test_input2))
        assert_with_message(
            1, count_occupied_seats_in_all_directions(2, 2, test_input2))
        given_input1 = [
            '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'
        ]
        given_input2 = [
            '#.##.##.##', '#######.##', '#.#.#..#..', '####.##.##',
            '#.##.##.##', '#.#####.##', '..#.#.....', '##########',
            '#.######.#', '#.#####.##'
        ]
        assert_with_message(given_input2, update_seats(given_input1))
        given_input3 = [
            '#.LL.LL.L#', '#LLLLLL.LL', 'L.L.L..L..', 'LLLL.LL.LL',
            'L.LL.LL.LL', 'L.LLLLL.LL', '..L.L.....', 'LLLLLLLLL#',
            '#.LLLLLL.L', '#.LLLLL.L#'
        ]
        assert_with_message(given_input3, update_seats(given_input2))
        given_input4 = [
            '#.L#.##.L#', '#L#####.LL', 'L.#.#..#..', '##L#.##.##',
            '#.##.#L.##', '#.#####.#L', '..#.#.....', 'LLL####LL#',
            '#.L#####.L', '#.L####.L#'
        ]
        assert_with_message(given_input4, update_seats(given_input3))
        given_input5 = [
            '#.L#.L#.L#', '#LLLLLL.LL', 'L.L.L..#..', '##LL.LL.L#',
            'L.LL.LL.L#', '#.LLLLL.LL', '..L.L.....', 'LLLLLLLLL#',
            '#.LLLLL#.L', '#.L#LL#.L#'
        ]
        assert_with_message(given_input5, update_seats(given_input4))
        given_input6 = [
            '#.L#.L#.L#', '#LLLLLL.LL', 'L.L.L..#..', '##L#.#L.L#',
            'L.L#.#L.L#', '#.L####.LL', '..#.#.....', 'LLL###LLL#',
            '#.LLLLL#.L', '#.L#LL#.L#'
        ]
        assert_with_message(given_input6, update_seats(given_input5))
        given_input7 = [
            '#.L#.L#.L#', '#LLLLLL.LL', 'L.L.L..#..', '##L#.#L.L#',
            'L.L#.LL.L#', '#.LLLL#.LL', '..#.L.....', 'LLL###LLL#',
            '#.LLLLL#.L', '#.L#LL#.L#'
        ]
        assert_with_message(given_input7, update_seats(given_input6))
        assert_with_message(26, get_num_occupied_after_updates(given_input1))
        assert_with_message(2144,
                            get_num_occupied_after_updates(get_input(11)))

        run()