|
| 1 | +# --- Day 1: Sonar Sweep --- |
| 2 | + |
| 3 | +## --- Part One --- |
| 4 | + |
| 5 | +You're minding your own business on a ship at sea when the overboard alarm goes off! You rush to see if you can help. |
| 6 | +Apparently, one of the Elves tripped and accidentally sent the sleigh keys flying into the ocean! |
| 7 | + |
| 8 | +Before you know it, you're inside a submarine the Elves keep ready for situations like this. It's covered in Christmas |
| 9 | +lights (because of course it is), and it even has an experimental antenna that should be able to track the keys if you |
| 10 | +can boost its signal strength high enough; there's a little meter that indicates the antenna's signal strength by |
| 11 | +displaying 0-50 stars. |
| 12 | + |
| 13 | +Your instincts tell you that in order to save Christmas, you'll need to get all fifty stars by December 25th. |
| 14 | + |
| 15 | +Collect stars by solving puzzles. Two puzzles will be made available on each day in the Advent calendar; |
| 16 | +the second puzzle is unlocked when you complete the first. Each puzzle grants one star. Good luck! |
| 17 | + |
| 18 | +As the submarine drops below the surface of the ocean, it automatically performs a sonar sweep of the nearby sea floor. |
| 19 | +On a small screen, the sonar sweep report (your puzzle input) appears: each line is a measurement of the sea floor depth as the sweep looks further and further away from the submarine. |
| 20 | + |
| 21 | +### For example, suppose you had the following report: |
| 22 | + |
| 23 | +```text |
| 24 | +199 |
| 25 | +200 |
| 26 | +208 |
| 27 | +210 |
| 28 | +200 |
| 29 | +207 |
| 30 | +240 |
| 31 | +269 |
| 32 | +260 |
| 33 | +263 |
| 34 | +``` |
| 35 | + |
| 36 | +This report indicates that, scanning outward from the submarine, the sonar sweep found depths |
| 37 | +of `199, 200, 208, 210`, and so on. |
| 38 | + |
| 39 | +The first order of business is to figure out how quickly the depth increases, just so you know what you're dealing |
| 40 | +with - you never know if the keys will get carried into deeper water by an ocean current or a fish or something. |
| 41 | + |
| 42 | +To do this, count the number of times a depth measurement increases from the previous measurement. ( |
| 43 | +There is no measurement before the first measurement.) In the example above, the changes are as follows: |
| 44 | + |
| 45 | +```text |
| 46 | +199 (N/A - no previous measurement) |
| 47 | +200 (increased) |
| 48 | +208 (increased) |
| 49 | +210 (increased) |
| 50 | +200 (decreased) |
| 51 | +207 (increased) |
| 52 | +240 (increased) |
| 53 | +269 (increased) |
| 54 | +260 (decreased) |
| 55 | +263 (increased) |
| 56 | +``` |
| 57 | + |
| 58 | +In this example, there are `7` measurements that are larger than the previous measurement. |
| 59 | + |
| 60 | +How many measurements are larger than the previous measurement? |
| 61 | + |
| 62 | +## --- Part Two --- |
| 63 | +Considering every single measurement isn't as useful as you expected: there's just too much noise in the data. |
| 64 | + |
| 65 | +Instead, consider sums of a three-measurement sliding window. Again considering the above example: |
| 66 | + |
| 67 | +```text |
| 68 | +199 A |
| 69 | +200 A B |
| 70 | +208 A B C |
| 71 | +210 B C D |
| 72 | +200 E C D |
| 73 | +207 E F D |
| 74 | +240 E F G |
| 75 | +269 F G H |
| 76 | +260 G H |
| 77 | +263 H |
| 78 | +``` |
| 79 | + |
| 80 | +Start by comparing the first and second three-measurement windows. The measurements in the first window are |
| 81 | +marked `A (199, 200, 208)`; their sum is `199 + 200 + 208 = 607`. |
| 82 | +The second window is marked `B (200, 208, 210)`; its sum is `618`. |
| 83 | +The sum of measurements in the second window is larger than the sum of the first, so this first comparison `increased`. |
| 84 | + |
| 85 | +Your goal now is to count the number of times the sum of measurements in this sliding window increases from the |
| 86 | +previous sum. So, compare `A` with `B`, then compare `B` with `C`, then `C` with `D`, and so on. |
| 87 | +Stop when there aren't enough measurements left to create a new three-measurement sum. |
| 88 | + |
| 89 | +In the above example, the sum of each three-measurement window is as follows: |
| 90 | + |
| 91 | +```text |
| 92 | +A: 607 (N/A - no previous sum) |
| 93 | +B: 618 (increased) |
| 94 | +C: 618 (no change) |
| 95 | +D: 617 (decreased) |
| 96 | +E: 647 (increased) |
| 97 | +F: 716 (increased) |
| 98 | +G: 769 (increased) |
| 99 | +H: 792 (increased) |
| 100 | +``` |
| 101 | + |
| 102 | +In this example, there are `5` sums that are larger than the previous sum. |
| 103 | + |
| 104 | +Consider sums of a three-measurement sliding window. How many sums are larger than the previous sum? |
0 commit comments