adventOfCode/challenges/2021/05-hydrothermalVenture
AKU 1f7931980a
Add missing typehint
Signed-off-by: AKU <tom@tdpain.net>
2021-12-06 21:19:41 +00:00
..
go Add 2021-05 in Golang 2021-12-05 21:38:55 +00:00
nim Add 2021-05 in Nim 2021-12-06 21:19:06 +00:00
py Add missing typehint 2021-12-06 21:19:41 +00:00
benchmark.json Update benchmarks 2021-12-05 21:39:24 +00:00
info.json Add 2021-05 in Python 2021-12-05 15:04:32 +00:00
napkinmath.jpg Add 2021-05 in Python 2021-12-05 15:04:32 +00:00
README.md Add 2021-05 in Python 2021-12-05 15:04:32 +00:00

Day 5: Hydrothermal Venture

Part one

  • Parse input and output a list of pairs of points.
  • Remove diagonal lines by filtering the list using the condition that p1.x == p2.x or p1.y == p2.y
  • Count overlapping points
    • Create a dictionary that uses the point coordinate as a key and contains an integer n for each key
    • Iterate over each line in the input, adding 1 to n for each coordinate in the line
      • The coordinates were founid by computing the x and y deltas between the two points that made up the line
      • The sign of the deltas determines the direction we step in
      • We then step through each point in the line based on the step directions until the final point is encountered
    • Iterate over all keys in the dictionary and count every point where n > 1

Part two

The same as part one, but without the list filtering step.


Involved literal napkin maths.

napkin math