aoc::year2024::day21

Function pad_routes

Source
fn pad_routes(
    combinations: &mut FastMap<(char, char), Vec<String>>,
    pad: &[(char, Point)],
    gap: Point,
)
Expand description

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:

  • 7 => A is only >>vvv.
  • 1 => 5 is ^> and >^.

We don’t consider routes that change direction more than once as these are always longer, for example 5 => A ignores the path v>v.