Expand description

This is my solution for Advent of Code - Day 8: Haunted Wasteland

Follows a map across a network of nodes. parse_input delegates to parse_instructions, parse_network, and parse_node to represent list of Instructions and Network or Nodes.

count_steps counts the steps from a specific starting node to one that satisfies a given predicate. count_parallel_steps determines how long the ghosts need to cycle until they all reach a destination, assuming they are all on a regular loop through the network.

Enums

  • An instruction determining which branch to follow when moving to the next node

Functions

  • Given a ghost starts at each of the nodes ending in A, and each follows the instructions in parallel, how many steps until they are all on a terminal node at the same time.
  • Follow the the list of instructions in a cycle until a destination node is reached
  • Parse the input as an Instruction line followed by a Network of Nodes
  • Parse a line of L and R as Instructions.
  • Parse each line of the spec as a labelled Node in a Network.
  • parse_node 🔒
    Parse a line in the format e.g. AAA = (BBB, CCC) as a node labelled AAA, linked to BBB and CCC on the left and right respectively.
  • The destination for part one is the specific node labelled ZZZ
  • Any node ending in Z counts as a destination for part 2
  • The entry point for running the solutions with the ‘real’ puzzle input.

Type Aliases

  • Network 🔒
    A networks of Nodes indexed by their label.
  • Node 🔒
    A node in the network defined by the labels of the nodes you can reach next