aoc::year2024

Module day21

Source
Expand description

ยงKeypad Conundrum

Each key sequence always end in A. This means that we can consider each group of button presses between As independently using a recursive approach with memoization to efficiently compute the minimum presses needed for any depth of chained robots.

Functionsยง

  • chain ๐Ÿ”’
  • dfs ๐Ÿ”’
  • pad_combinations ๐Ÿ”’
    Compute keypresses needed for all possible transitions for both numeric and directional keypads. There are no distinct pairs shared between the keypads so they can use the same map without conflict.
  • pad_routes ๐Ÿ”’
    Each route between two keys has 2 possibilites, horizontal first or vertical first. We skip any route that would cross the gap and also avoid adding the same route twice when a key is in a straight line (e.g. directly above/below or left/right). For example:
  • Convert codes to pairs of the sequence itself with the numeric part. The pad combinations are the same between both parts so only need to be computed once.

Type Aliasesยง