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 (2408B)


      1--- Day 1: Sonar Sweep ---
      2
      3You're minding your own business on a ship at sea when the overboard alarm goes off! You rush to see
      4if you can help. Apparently, one of the Elves tripped and accidentally sent the sleigh keys flying
      5into the ocean!
      6
      7Before you know it, you're inside a submarine the Elves keep ready for situations like this. It's
      8covered in Christmas lights (because of course it is), and it even has an experimental antenna that
      9should be able to track the keys if you can boost its signal strength high enough; there's a little
     10meter that indicates the antenna's signal strength by displaying 0-50 stars.
     11
     12Your instincts tell you that in order to save Christmas, you'll need to get all fifty
     13stars by December 25th.
     14
     15Collect stars by solving puzzles.  Two puzzles will be made available on each day in the Advent
     16calendar; the second puzzle is unlocked when you complete the first.  Each puzzle grants
     17one star. Good luck!
     18
     19As the submarine drops below the surface of the ocean, it automatically performs a sonar sweep of
     20the nearby sea floor. On a small screen, the sonar sweep report (your puzzle input) appears: each
     21line is a measurement of the sea floor depth as the sweep looks further and further away from the
     22submarine.
     23
     24For example, suppose you had the following report:
     25
     26199
     27200
     28208
     29210
     30200
     31207
     32240
     33269
     34260
     35263
     36
     37This report indicates that, scanning outward from the submarine, the sonar sweep found depths of
     38199, 200, 208, 210, and so on.
     39
     40The first order of business is to figure out how quickly the depth increases, just so you know what
     41you're dealing with - you never know if the keys will get carried into deeper water by an ocean
     42current or a fish or something.
     43
     44To do this, count the number of times a depth measurement increases from the previous
     45measurement. (There is no measurement before the first measurement.) In the example above, the
     46changes are as follows:
     47
     48199 (N/A - no previous measurement)
     49200 (increased)
     50208 (increased)
     51210 (increased)
     52200 (decreased)
     53207 (increased)
     54240 (increased)
     55269 (increased)
     56260 (decreased)
     57263 (increased)
     58
     59In this example, there are 7 measurements that are larger than the previous
     60measurement.
     61
     62How many measurements are larger than the previous measurement?
     63
     64