Source: Day 3: Gear Ratios
Full solution for today (spoilers!). Note: I did slightly change my solutions template after writing this blog post, so the final solution is structured slightly differently than the code in this post. The functionality itself hasn’t changed.
Part 1
Take as input a 2D grid of numbers or symbols (
.
represents empty space). Numbers will be 1 or more digits written horizontally which should be concatenated (.467*
is the number467
followed by the symbol*
).Sum all numbers that are adjacent (including diagonally) to at least one symbol.