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()
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()
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()
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()
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()
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()
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()
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()
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()
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()
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()
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()
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()