Expand description

This is my solution for Advent of Code - Day 9: Mirage Maintenance

parse_input uses parse_line to interpret the puzzle input as sequences of integers.

analyse_sequences hands analysing each sequence to the provided extrapolator, either extrapolate_sequence_forwards for part 1 or extrapolate_sequence_backwards for part 2.

Both extrapolators rely on build_delta_sequences, which uses iterate to recursively generate the a sequence of sequences, each sequence in turn being generated by build_delta_sequence from the previous sequence.

Functions

  • Extrapolate each sequence in the list, and sum the extrapolated values
  • Generate a sequence of the difference between each consecutive pair of numbers
  • Given a list of integers, return the sequence of sequences generated by recursively calling build_delta_sequence on the previous sequence until a sequence of 0s is generated
  • Unwrap the sequence of delta sequences to extrapolate the previous value in the original sequence. This is equivalent recursively subtracting the first value in the sequence.
  • Unwrap the sequence of delta sequences to extrapolate the next value in the original sequence. This is equivalent to the sum of the last value in each of the delta sequences
  • Parse each line as a sequence of integers
  • parse_line 🔒
    Parse a line as a space separated list of integers
  • The entry point for running the solutions with the ‘real’ puzzle input.