|
| 1 | +# Day 9: Mirage Maintenance --- |
| 2 | +You ride the camel through the sandstorm and stop where the ghost's maps told you to stop. The sandstorm subsequently |
| 3 | +subsides, somehow seeing you standing at an **oasis**! |
| 4 | + |
| 5 | +The camel goes to get some water and you stretch your neck. As you look up, you discover what must be yet another giant |
| 6 | +floating island, this one made of metal! That must be where the **parts to fix the sand machines** come from. |
| 7 | + |
| 8 | +There's even a [hang glider](https://en.wikipedia.org/wiki/Hang_gliding) partially buried in the sand here; once the |
| 9 | +sun rises and heats up the sand, you might be able to use the glider and the hot air to get all the way up to the metal |
| 10 | +island! |
| 11 | + |
| 12 | +While you wait for the sun to rise, you admire the oasis hidden here in the middle of Desert Island. It must have a |
| 13 | +delicate ecosystem; you might as well take some ecological readings while you wait. Maybe you can report any |
| 14 | +environmental instabilities you find to someone so the oasis can be around for the next sandstorm-worn traveler. |
| 15 | + |
| 16 | +You pull out your handy **Oasis And Sand Instability Sensor** and analyze your surroundings. The OASIS produces a |
| 17 | +report of many values and how they are changing over time (your puzzle input). Each line in the report contains the |
| 18 | +**history** of a single value. For example: |
| 19 | +``` |
| 20 | +0 3 6 9 12 15 |
| 21 | +1 3 6 10 15 21 |
| 22 | +10 13 16 21 30 45 |
| 23 | +``` |
| 24 | +To best protect the oasis, your environmental report should include a **prediction of the next value** in each history. |
| 25 | +To do this, start by making a new sequence from the **difference at each step** of your history. If that sequence is |
| 26 | +**not** all zeroes, repeat this process, using the sequence you just generated as the input sequence. Once all of the |
| 27 | +values in your latest sequence are zeroes, you can extrapolate what the next value of the original history should be. |
| 28 | + |
| 29 | +In the above dataset, the first history is `0 3 6 9 12 15`. Because the values increase by `3` each step, the first |
| 30 | +sequence of differences that you generate will be `3 3 3 3 3`. Note that this sequence has one fewer value than the |
| 31 | +input sequence because at each step it considers two numbers from the input. Since these values aren't **all zero**, |
| 32 | +repeat the process: the values differ by `0` at each step, so the next sequence is `0 0 0 0`. This means you have |
| 33 | +enough information to extrapolate the history! Visually, these sequences can be arranged like this: |
| 34 | +``` |
| 35 | +0 3 6 9 12 15 |
| 36 | + 3 3 3 3 3 |
| 37 | + 0 0 0 0 |
| 38 | +``` |
| 39 | +To extrapolate, start by adding a new zero to the end of your list of zeroes; because the zeroes represent differences |
| 40 | +between the two values above them, this also means there is now a placeholder in every sequence above it: |
| 41 | +``` |
| 42 | +0 3 6 9 12 15 _B_ |
| 43 | + 3 3 3 3 3 _A_ |
| 44 | + 0 0 0 0 _0_ |
| 45 | +``` |
| 46 | +You can then start filling in placeholders from the bottom up. `A` needs to be the result of increasing `3` (the value |
| 47 | +to its left) by `0` (the value below it); this means `A` must be `3`: |
| 48 | +``` |
| 49 | +0 3 6 9 12 15 B |
| 50 | + 3 3 3 3 _3_ _3_ |
| 51 | + 0 0 0 0 _0_ |
| 52 | +``` |
| 53 | +Finally, you can fill in `B`, which needs to be the result of increasing `15` (the value to its left) by `3` (the value |
| 54 | +below it), or **`18`**: |
| 55 | +``` |
| 56 | +0 3 6 9 12 _15_ _18_ |
| 57 | + 3 3 3 3 3 _3_ |
| 58 | + 0 0 0 0 0 |
| 59 | +``` |
| 60 | +So, the next value of the first history is **`18`**. |
| 61 | + |
| 62 | +Finding all-zero differences for the second history requires an additional sequence: |
| 63 | +``` |
| 64 | +1 3 6 10 15 21 |
| 65 | + 2 3 4 5 6 |
| 66 | + 1 1 1 1 |
| 67 | + 0 0 0 |
| 68 | +``` |
| 69 | +Then, following the same process as before, work out the next value in each sequence from the bottom up: |
| 70 | +``` |
| 71 | +1 3 6 10 15 21 _28_ |
| 72 | + 2 3 4 5 6 _7_ |
| 73 | + 1 1 1 1 _1_ |
| 74 | + 0 0 0 _0_ |
| 75 | +``` |
| 76 | +So, the next value of the second history is **`28`**. |
| 77 | + |
| 78 | +The third history requires even more sequences, but its next value can be found the same way: |
| 79 | +``` |
| 80 | +10 13 16 21 30 45 _68_ |
| 81 | + 3 3 5 9 15 _23_ |
| 82 | + 0 2 4 6 _8_ |
| 83 | + 2 2 2 _2_ |
| 84 | + 0 0 _0_ |
| 85 | +``` |
| 86 | +So, the next value of the third history is **`68`**. |
| 87 | + |
| 88 | +If you find the next value for each history in this example and add them together, you get **`114`**. |
| 89 | + |
| 90 | +Analyze your OASIS report and extrapolate the next value for each history. **What is the sum of these extrapolated |
| 91 | +values**? |
0 commit comments