aoc-2021-rust

Advent of Code 2021 Solutions in Rust
git clone https://git.sinitax.com/sinitax/aoc-2021-rust
Log | Files | Refs | README | sfeed.txt

part1 (1853B)


      1--- Day 5: Hydrothermal Venture ---
      2
      3You come across a field of hydrothermal vents on the ocean floor! These vents constantly produce
      4large, opaque clouds, so it would be best to avoid them if possible.
      5
      6They tend to form in lines; the submarine helpfully produces a list of nearby lines of vents (your
      7puzzle input) for you to review. For example:
      8
      90,9 -> 5,9
     108,0 -> 0,8
     119,4 -> 3,4
     122,2 -> 2,1
     137,0 -> 7,4
     146,4 -> 2,0
     150,9 -> 2,9
     163,4 -> 1,4
     170,0 -> 8,8
     185,5 -> 8,2
     19
     20Each line of vents is given as a line segment in the format x1,y1 -> x2,y2 where x1,y1 are the
     21coordinates of one end the line segment and x2,y2 are the coordinates of the other end. These line
     22segments include the points at both ends. In other words:
     23
     24
     25 - An entry like 1,1 -> 1,3 covers points 1,1, 1,2, and 1,3.
     26
     27 - An entry like 9,7 -> 7,7 covers points 9,7, 8,7, and 7,7.
     28
     29
     30For now, only consider horizontal and vertical lines: lines where either x1 = x2 or y1 = y2.
     31
     32So, the horizontal and vertical lines from the above list would produce the following diagram:
     33
     34.......1..
     35..1....1..
     36..1....1..
     37.......1..
     38.112111211
     39..........
     40..........
     41..........
     42..........
     43222111....
     44
     45In this diagram, the top left corner is 0,0 and the bottom right corner is 9,9. Each position is
     46shown as the number of lines which cover that point or . if no line covers that point. The top-left
     47pair of 1s, for example, comes from 2,2 -> 2,1; the very bottom row is formed by the overlapping
     48lines 0,9 -> 5,9 and 0,9 -> 2,9.
     49
     50To avoid the most dangerous areas, you need to determine the number of points where at least two
     51lines overlap. In the above example, this is anywhere in the diagram with a 2 or larger - a total of
     525 points.
     53
     54Consider only horizontal and vertical lines. At how many points do at least two lines overlap?
     55
     56