AoC 2021 D5: Hydrothermal Venture
| Problem statement | Source code | Tags: Grid walking
← Previous Back to AoC Index Next →
Part 1
It happens that the coordinates are less than 1000, so this is doable with a fixed-size 2D array of size 1000x1000 without any kind of coordinate compression (coordinate compression won't work for part 2 with diagonal lines anyway). Each cell in the grid represents how many lines pass through that point.
Part 2
We just need to add another case for diagonal lines. This can be done by calculating the step for x and y separately, then iterating from the start point to the end point using those steps.