def lantern_fish(num_ticks: int): data = puzzle_input_to_str(6, True) fish_dict = parse_lantern_fish_list(data[0]) for _ in range(num_ticks): fish_dict = lantern_fish_tick(fish_dict) total = sum(fish_dict.values()) return total
def smoke_basin_2(): puzzle_input = puzzle_input_to_str(9) numbers = parse_smoke_basin_string(puzzle_input) grid = Grid(numbers) low_basins = smoke_low_basins(grid) ordered_basins = sorted(low_basins) return ordered_basins[-1] * ordered_basins[-2] * ordered_basins[-3]
def seven_segment_search_2() -> int: total = 0 puzzle_input = puzzle_input_to_str(8) signal_patterns = parse_signal_patterns(puzzle_input) for signal_pattern in signal_patterns: number = unscramble_output_pattern(signal_pattern) total += int(number) return total
def binary_diagnostic1(): bits_list = puzzle_input_to_str(3, strip=True) gamma_rate_bits: list[int] = list() for i in range(len(bits_list[0])): gamma_rate_bits.append(most_common_bit(bits_list, i)) eplison_rate_bits = [bit ^ 1 for bit in gamma_rate_bits] gamma_rate_decimal = bits_to_decimal(gamma_rate_bits, "big") epsilon_rate_decimal = bits_to_decimal(eplison_rate_bits, "big") return gamma_rate_decimal * epsilon_rate_decimal
def smoke_basin_1(): puzzle_input = puzzle_input_to_str(9) numbers = parse_smoke_basin_string(puzzle_input) grid = Grid(numbers) low_points = smoke_low_points(grid) total = 0 for p in low_points: total += p + 1 return total
def syntax_scoring_2(): puzzle_input = puzzle_input_to_str(10, strip=True) scores: list[int] = list() for line in puzzle_input: illegal_character = syntax_parser(line) if illegal_character != "": continue autocomplete_chars = syntax_autocomplete(line) score = score_autocomplete(autocomplete_chars) scores.append(score) scores.sort() return scores[len(scores) // 2]
def dive1(): positions = puzzle_input_to_str(2) x = 0 depth = 0 for position in positions: direction, magnitude = position.split() magnitude = int(magnitude) if direction == "forward": x += magnitude if direction == "down": depth += magnitude if direction == "up": depth -= magnitude return x * depth
def syntax_scoring_1(): puzzle_input = puzzle_input_to_str(10, strip=True) closing_char_map: dict[str, int] = { ")": 3, "]": 57, "}": 1197, ">": 25137, "": 0 } total = 0 for line in puzzle_input: illegal_char = syntax_parser(line) score = closing_char_map[illegal_char] total += score return total
def binary_diagnostic2() -> int: bits_list = puzzle_input_to_str(3, strip=True) oxygen_generator_rating = calculate_oxygen_generator_rating( bits_list.copy()) co2_scrubber_rating = calculate_co2_scrubber_rating(bits_list.copy()) return oxygen_generator_rating * co2_scrubber_rating
def seven_segment_search_1() -> int: puzzle_input = puzzle_input_to_str(8) result = output_pattern_counts(puzzle_input) return result
def the_treachery_of_whales(cost_function: Callable[[int, int], int]) -> int: puzzle_input = puzzle_input_to_str(7) crab_positions = [int(x) for x in puzzle_input[0].split(",")] _, min_fuel = minimum_fuel(crab_positions, cost_function) return min_fuel
def hydrothermal_venture2() -> int: puzzle_input = puzzle_input_to_str(5, True) vent_vectors = [parse_vent_line(vent_line) for vent_line in puzzle_input] result = hydrothermal_venture(vent_vectors) return result
def giant_squid2() -> int: puzzle_input = puzzle_input_to_str(4, strip=True) bingo = puzzle_input_to_bingo(puzzle_input) return last_winning_board(bingo)