def test_puzzle_input(self): with open(get_puzzle_input_path(os.path.dirname(__file__))) as content: map = [line.rstrip() for line in content] map_encounters = walk_the_map(map) trees_encountered = sum(1 for x in map_encounters if x.encountered == "#") self.assertEqual(trees_encountered, 292)
def test_read_passwords_from_puzzle_input(self): with open(get_puzzle_input_path(os.path.dirname(__file__))) as content: ss = content.read() passports = parse(ss) valid_passports = [p for p in passports if is_valid_passport(p)] # print(valid_passports) self.assertEqual(len(valid_passports), 228)
def test_part_one(self): with open(get_puzzle_input_path(os.path.dirname(__file__))) as content: content = content.read() z = seek_first_invalid_number(content, 25) print(z) self.assertEqual(z, 375054920)
def test_puzzle_input_combinations_part_one(self): expenses = read_numbers_from_file( get_puzzle_input_path(os.path.dirname(__file__))) candidate = combination_that_sums_2020(expenses, 2) self.assertEqual(candidate[0] * candidate[1], 55776)
def test_puzzle_input_part_one(self): with open(get_puzzle_input_path(os.path.dirname(__file__))) as content: puzzle_input = content.read().splitlines() seen_joltage_steps = organise_plugs(puzzle_input) self.assertEqual(seen_joltage_steps, {1: 73, 3: 31}) self.assertEqual(seen_joltage_steps[1] * seen_joltage_steps[3], 2263)
def test_puzzle_input_part_one(self): with open(get_puzzle_input_path(os.path.dirname(__file__))) as content: ss = content.read() bags = Bag.parse(ss) can_hold_gold = bags['shiny gold'].can_be_in() self.assertEqual(len(can_hold_gold), 246)
def test_read_passwords_from_puzzle_input_part_two(self): with open(get_puzzle_input_path(os.path.dirname(__file__))) as content: ss = content.read() passports = parse(ss) valid_passports = [ p for p in passports if PartTwoValidator.validate(p)] # print(valid_passports) self.assertEqual(len(valid_passports), 175)
def test_puzzle_input_part_two(self): with open(get_puzzle_input_path(os.path.dirname(__file__))) as content: ss = content.read() bags = Bag.parse(ss) gold_contains = bags['shiny gold'].count_children() self.assertEqual(gold_contains, 2976)
def test_occupied_seats_after_puzzle_input_stabilizes(self): with open(get_puzzle_input_path(os.path.dirname(__file__))) as content: puzzle_input = content.read() grid = Grid(puzzle_input) next_grid = grid.tick() while grid != next_grid: grid = next_grid next_grid = next_grid.tick() self.assertEqual(next_grid.occupied_seats(), 2412)
def test_occupied_seats_after_puzzle_input_stabilizes_part_two(self): with open(get_puzzle_input_path(os.path.dirname(__file__))) as content: puzzle_input = content.read() grid = Grid(puzzle_input, LineOfSightAdjacentSeats, 5) next_grid = grid.tick() while grid != next_grid: grid = next_grid next_grid = next_grid.tick() self.assertEqual(next_grid.occupied_seats(), 2176)
def test_part_one_puzzle_input(self): with open(get_puzzle_input_path(os.path.dirname(__file__))) as content: puzzle_input = content.read() parts = parse_input(puzzle_input) actual = check_ticket(parts) invalids = flatten(actual) self.assertEqual( 29019, sum(invalids) )
def test_puzzle_input_part_two(self): with open(get_puzzle_input_path(os.path.dirname(__file__))) as content: map = [line.rstrip() for line in content] different_slopes = [ count_trees_encountered(map, 1, 1), count_trees_encountered(map, 3, 1), count_trees_encountered(map, 5, 1), count_trees_encountered(map, 7, 1), count_trees_encountered(map, 1, 2), ] self.assertEqual(reduce(operator.mul, different_slopes), 9354744432)
def test_program_with_puzzle_input(self): program = VersionOneDecoderProgram() with open(get_puzzle_input_path(os.path.dirname(__file__))) as content: input_lines = [ line.strip() for line in content.read().splitlines() if len(line.strip()) > 0 ] for line in input_lines: program.process_line(line) self.assertEqual(program.sum_memory(), 16003257187056)
def test_ship_following_puzzle_input(self): with open(get_puzzle_input_path(os.path.dirname(__file__))) as content: puzzle_input = [ s.strip() for s in content.read().splitlines() if len(s.strip()) > 0 ] ship = FreeFloatingShip() for i in puzzle_input: ship.navigate(i) self.assertEqual(ship.manhattan_distance_travelled(), 1007)
def test_puzzle_input_part_two(self): with open(get_puzzle_input_path(os.path.dirname(__file__))) as content: ss = content.read().split("\n") seat_ids = [generate_id(s) for s in ss] sorted_seat_ids = sorted(seat_ids) candidates = [] for index in range(1, len(sorted_seat_ids)): current = sorted_seat_ids[index] previous = sorted_seat_ids[index-1] if current - previous != 1: candidates.append(current-1) my_seat = candidates[0] self.assertEqual(my_seat, 504)
def test_something_part_two_puzzle_input(self): with open(get_puzzle_input_path(os.path.dirname(__file__))) as content: puzzle_input = content.read() parts = parse_input(puzzle_input) valids = get_valid_tickets(parts) candidates = map_fields(valids, parts['rules']) departure_fields = [f['position'] for f in candidates if f['spec'].startswith('departure')] my_departure_fields = [] for departure_field in departure_fields: my_departure_fields.append(parts['own_ticket'][departure_field]) departure_fields_product = math.prod(my_departure_fields) self.assertEqual(517827547723, departure_fields_product)
def test_part_two(self): with open(get_puzzle_input_path(os.path.dirname(__file__))) as content: content = content.read() boot_code = Console.boot_code_from(content) current = 0 patch_index = -1 patch_in: str = "not set" for current in range(0, len(boot_code)): if boot_code[current].startswith('jmp'): if self.patch_code(boot_code, current, "nop"): patch_index = current patch_in = "nop" elif boot_code[current].startswith('nop'): if self.patch_code(boot_code, current, "jmp"): patch_index = current patch_in = "jmp" console = self.patch_code(boot_code, patch_index, patch_in) self.assertEqual(console.terminated, True) self.assertEqual(console.accumulator, 501)
def test_valid_passwords_puzzle_input(self): policyExamples = read_from_file( get_puzzle_input_path(os.path.dirname(__file__))) validPasswords = checkPasswordValidity(policyExamples) self.assertEqual(len(validPasswords), 536)
def test_part_one(self): with open(get_puzzle_input_path(os.path.dirname(__file__))) as content: ss = content.read() console = Console.parse(ss) console.run() self.assertEqual(console.accumulator, 1217)
def test_sum_counts_for_puzzle_input_part_two(self): with open(get_puzzle_input_path(os.path.dirname(__file__))) as content: ss = content.read() sum_of_counts = sum_counts(everyone_yes(split_groups(ss))) self.assertEqual(sum_of_counts, 3476)
def test_encryption_weakness_with_puzzle_input(self): with open(get_puzzle_input_path(os.path.dirname(__file__))) as content: puzzle_input = content.read() weakness = find_encryption_weakness(puzzle_input, 375054920) self.assertEqual(weakness, 54142584)
def test_puzzle_input_part_one(self): with open(get_puzzle_input_path(os.path.dirname(__file__))) as content: ss = content.read().split("\n") seat_ids = [generate_id(s) for s in ss] max_seat_id = max(seat_ids) self.assertEqual(max_seat_id, 878)
def test_valid_passwords_puzzle_input_part_two(self): policyExamples = read_from_file( get_puzzle_input_path(os.path.dirname(__file__))) validPasswords = checkPasswordValidityPartTwo(policyExamples) self.assertLess(len(validPasswords), 786) self.assertEqual(len(validPasswords), 558)