advent_of_code_2024

Module day_7

source
Expand description

This is my solution for Advent of Code - Day 7: Bridge Repair

parse_input uses parse_equation to create an Equation for each row of the inout file.

calculate_calibration_total uses is_solvable to solve both parts, part_1_operations and part_2_operations providing the different operation lists.

StructsΒ§

  • Equation πŸ”’
    An equation missing operators, stored as a target number, the running total and the numbers that have yet to be combined into to the total.

FunctionsΒ§

  • The puzzle solution is the sum of the equations that are solvable.
  • is_solvable πŸ”’
    Do depth-first search to solve the equation using permutations of the available operators, returning true if there is at least one permutation of operators that results in the target number. Operations must increase the total, or return None for all possible inputs.
  • parse_equation πŸ”’
    Parse a line of input as an Equation. The first operator is applied to the first two numbers, so the first number in the list is used to initialise the running total.
  • parse_input πŸ”’
    Use parse_equation to parse each line of the input
  • The operations available when solving part 1, add and multiply
  • The operations available when solving part 2, add multiply, and concat
  • The entry point for running the solutions with the β€˜real’ puzzle input.

Type AliasesΒ§

  • Operation πŸ”’
    An operation to apply with the running total on the lhs, and the next number as the rhs.