Module aoc::y22d09

source ·
Expand description

Advent of Code 2022 Day 9: https://adventofcode.com/2022/day/9

The logic in this solution is a bit verbose and could probably be consolidated some, but it’s easier for me to grok expanded out. I generalized the solution to operate on an arbitrary number of knots, as part one of the challenge can be thought of as a rope with only two knots. Obviously, this doesn’t work if the number of knots is less than two.

To keep track of which positions the tail knot has visited we use a std::collections::HashSet with tuples of x,y coordinates so that at the end we can just return the size of the set to get the total number of locations visited.

Functions§

  • The solution for the day nine challenge.