Advent of Code 2021 — Day 5
Hydrothermal Venture
https://adventofcode.com/2021/day/5
Part 1 — This is a day to make sure you know your multi-dimensional arrays in your programming language and can trace lines given two end points. I modeled this in two ways — with a filled NxN grid and with a sparse grid (Hash
). In these examples, the NxN grid was almost an order of magnitude faster. For the NxN grid, also made the assumption that the grid was square, which is good enough for this problem.

Once we process the horizontal and vertical lines in the input, we count the grid squares that have more than one line overlapping it. I use the enumerable
methods of count
and sum
to count the overlaps in the grid.

Part 2 — The only difference in part 2 is that we now process the whole input, including the diagonal lines.
Source on github