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 returnNone
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 πUseparse_equation
to parse each line of the input - part_
1_ πoperations The operations available when solving part 1, add and multiply - part_
2_ πoperations 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.