advent_of_code_2024

Module day_8

source
Expand description

This is my solution for Advent of Code - Day 8: Resonant Collinearity

parse_input converts the input file to an AntennaMap which stores a HashMap of frequency to list of antenna coordinates, as well as the upper bounds of the grid.

count_antinodes_for_map solves both parts, breaking the work down into calling find_antinodes_for_frequency for each frequency in the map. This in turn uses find_antinodes_for_pair on each combination of antenna in the frequency group.

sequence_from_antenna extrapolates the line defined by a pair of antenna, in one direction and antinode_pair_sequence_modifier and resonant_harmonies_sequence_modifier handle selecting the right node(s) for part 1 and 2 respectively. find_antinodes_for_pair uses sequence_from_antenna starting from each node in the pair.

StructsΒ§

  • AntennaMap πŸ”’
    Represent the puzzle grid by its upper bounds and the position of antenna grouped by frequency

FunctionsΒ§

  • Part 1 - Select only the first node beyond the origin
  • For all frequencies un the map, find all the antinodes, then count unique coordinates.
  • Combine all pairs of antenna in a frequency and return the unique antinodes
  • Fine the antinodes by determining the coordinate delta between two antinodes, extrapolating the line from both ends, applying the SequenceModifier relevant to the part being solved.
  • parse_input πŸ”’
    Converts the text input into the internal representation
  • Part 2 - Select all nodes including the origin - essentially the identity function
  • The entry point for running the solutions with the β€˜real’ puzzle input.
  • Extrapolate from a point along a delta whilst it’s within the bounds of the antenna map

Type AliasesΒ§

  • Coordinate πŸ”’
    A coordinate on the grid
  • SequenceModifier πŸ”’
    This differentiates the two parts by allowing outside control over which nodes are selected when extrapolating the line between two antenna