Alex Eversmeyer

Posted on

# Advent of Code, Days 9-11

It's been a very interesting few days in the Advent of Code challenge. Day 9 has probably been my favorite so far: the challenge was to find the low points on a heightmap (an array of numbers), and then find the associated basins (defined as any numbers less than 9 connected to the low point, excluding diagonals).

``````2199943210
3987894921
9856789892
8767896789
9899965678

A sample heightmap.
``````

The first part was not particularly difficult. It required coding some logic to check corners and edges, since some adjacent coordinates would be outside the map, as well as iterating through the inner parts of the map to locate the numbers lower than all four other numbers to the left, right, up, and down.

The second part of the day's puzzle is where things really got fun: discovering the size of each basin connected to a low spot. To do so required a recursive function with a little twist to it (relative to the basic recursion I've used once or twice before). It felt really good to not only work out how to solve this problem, but to also code the solution. I also figured out how to clean up my function to avoid repetition and look clean, too!

Yesterday's and today's puzzles felt a little simpler, and today's used some code similar to the mapping functions from day 9. The trickiest part for me was working out how to reference all eight locations next to a given coordinate, including diagonals, without referencing the original coordinate.

The Advent of Code is nearing the halfway point. Looking forward to seeing where the puzzles go from here, both in terms of theme as well as difficulty!