Refactor framework to support more years
This commit is contained in:
2000
data/Y21/day1/data.txt
Normal file
2000
data/Y21/day1/data.txt
Normal file
File diff suppressed because it is too large
Load Diff
10
data/Y21/day1/example.txt
Normal file
10
data/Y21/day1/example.txt
Normal file
@ -0,0 +1,10 @@
|
||||
199
|
||||
200
|
||||
208
|
||||
210
|
||||
200
|
||||
207
|
||||
240
|
||||
269
|
||||
260
|
||||
263
|
91
data/Y21/day1/puzzle.md
Normal file
91
data/Y21/day1/puzzle.md
Normal file
@ -0,0 +1,91 @@
|
||||
# Day 1: Sonar Sweep
|
||||
|
||||
[https://adventofcode.com/2021/day/1](https://adventofcode.com/2021/day/1)
|
||||
|
||||
## Description
|
||||
|
||||
### Part One
|
||||
|
||||
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. Apparently, one of the Elves tripped and accidentally sent the sleigh keys flying into the ocean!
|
||||
|
||||
Before you know it, you're inside a submarine the Elves keep ready for situations like this. It's covered in Christmas lights (because of course it is), and it even has an experimental antenna that should be able to track the keys if you can boost its signal strength high enough; there's a little meter that indicates the antenna's signal strength by displaying 0-50 _stars_.
|
||||
|
||||
Your instincts tell you that in order to save Christmas, you'll need to get all _fifty stars_ by December 25th.
|
||||
|
||||
Collect stars by solving puzzles. Two puzzles will be made available on each day in the Advent calendar; the second puzzle is unlocked when you complete the first. Each puzzle grants _one star_. Good luck!
|
||||
|
||||
As the submarine drops below the surface of the ocean, it automatically performs a sonar sweep of the nearby sea floor. 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.
|
||||
|
||||
For example, suppose you had the following report:
|
||||
|
||||
199
|
||||
200
|
||||
208
|
||||
210
|
||||
200
|
||||
207
|
||||
240
|
||||
269
|
||||
260
|
||||
263
|
||||
|
||||
|
||||
This report indicates that, scanning outward from the submarine, the sonar sweep found depths of `199`, `200`, `208`, `210`, and so on.
|
||||
|
||||
The first order of business is to figure out how quickly the depth increases, just so you know what you're dealing with - you never know if the keys will get <span title="Does this premise seem fishy to you?">carried into deeper water</span> by an ocean current or a fish or something.
|
||||
|
||||
To do this, count _the number of times a depth measurement increases_ from the previous measurement. (There is no measurement before the first measurement.) In the example above, the changes are as follows:
|
||||
|
||||
199 (N/A - no previous measurement)
|
||||
200 (increased)
|
||||
208 (increased)
|
||||
210 (increased)
|
||||
200 (decreased)
|
||||
207 (increased)
|
||||
240 (increased)
|
||||
269 (increased)
|
||||
260 (decreased)
|
||||
263 (increased)
|
||||
|
||||
|
||||
In this example, there are _`7`_ measurements that are larger than the previous measurement.
|
||||
|
||||
_How many measurements are larger than the previous measurement?_
|
||||
|
||||
### Part Two
|
||||
|
||||
Considering every single measurement isn't as useful as you expected: there's just too much noise in the data.
|
||||
|
||||
Instead, consider sums of a _three-measurement sliding window_. Again considering the above example:
|
||||
|
||||
199 A
|
||||
200 A B
|
||||
208 A B C
|
||||
210 B C D
|
||||
200 E C D
|
||||
207 E F D
|
||||
240 E F G
|
||||
269 F G H
|
||||
260 G H
|
||||
263 H
|
||||
|
||||
|
||||
Start by comparing the first and second three-measurement windows. The measurements in the first window are marked `A` (`199`, `200`, `208`); their sum is `199 + 200 + 208 = 607`. The second window is marked `B` (`200`, `208`, `210`); its sum is `618`. The sum of measurements in the second window is larger than the sum of the first, so this first comparison _increased_.
|
||||
|
||||
Your goal now is to count _the number of times the sum of measurements in this sliding window increases_ from the previous sum. So, compare `A` with `B`, then compare `B` with `C`, then `C` with `D`, and so on. Stop when there aren't enough measurements left to create a new three-measurement sum.
|
||||
|
||||
In the above example, the sum of each three-measurement window is as follows:
|
||||
|
||||
A: 607 (N/A - no previous sum)
|
||||
B: 618 (increased)
|
||||
C: 618 (no change)
|
||||
D: 617 (decreased)
|
||||
E: 647 (increased)
|
||||
F: 716 (increased)
|
||||
G: 769 (increased)
|
||||
H: 792 (increased)
|
||||
|
||||
|
||||
In this example, there are _`5`_ sums that are larger than the previous sum.
|
||||
|
||||
Consider sums of a three-measurement sliding window. _How many sums are larger than the previous sum?_
|
1000
data/Y21/day2/data.txt
Normal file
1000
data/Y21/day2/data.txt
Normal file
File diff suppressed because it is too large
Load Diff
6
data/Y21/day2/example.txt
Normal file
6
data/Y21/day2/example.txt
Normal file
@ -0,0 +1,6 @@
|
||||
forward 5
|
||||
down 5
|
||||
forward 8
|
||||
up 3
|
||||
down 8
|
||||
forward 2
|
67
data/Y21/day2/puzzle.md
Normal file
67
data/Y21/day2/puzzle.md
Normal file
@ -0,0 +1,67 @@
|
||||
# Day 2: Dive!
|
||||
|
||||
[https://adventofcode.com/2021/day/2](https://adventofcode.com/2021/day/2)
|
||||
|
||||
## Description
|
||||
|
||||
### Part One
|
||||
|
||||
Now, you need to figure out how to <span title="Tank, I need a pilot program for a B212 helicopter.">pilot this thing</span>.
|
||||
|
||||
It seems like the submarine can take a series of commands like `forward 1`, `down 2`, or `up 3`:
|
||||
|
||||
* `forward X` increases the horizontal position by `X` units.
|
||||
* `down X` _increases_ the depth by `X` units.
|
||||
* `up X` _decreases_ the depth by `X` units.
|
||||
|
||||
Note that since you're on a submarine, `down` and `up` affect your _depth_, and so they have the opposite result of what you might expect.
|
||||
|
||||
The submarine seems to already have a planned course (your puzzle input). You should probably figure out where it's going. For example:
|
||||
|
||||
forward 5
|
||||
down 5
|
||||
forward 8
|
||||
up 3
|
||||
down 8
|
||||
forward 2
|
||||
|
||||
|
||||
Your horizontal position and depth both start at `0`. The steps above would then modify them as follows:
|
||||
|
||||
* `forward 5` adds `5` to your horizontal position, a total of `5`.
|
||||
* `down 5` adds `5` to your depth, resulting in a value of `5`.
|
||||
* `forward 8` adds `8` to your horizontal position, a total of `13`.
|
||||
* `up 3` decreases your depth by `3`, resulting in a value of `2`.
|
||||
* `down 8` adds `8` to your depth, resulting in a value of `10`.
|
||||
* `forward 2` adds `2` to your horizontal position, a total of `15`.
|
||||
|
||||
After following these instructions, you would have a horizontal position of `15` and a depth of `10`. (Multiplying these together produces _`150`_.)
|
||||
|
||||
Calculate the horizontal position and depth you would have after following the planned course. _What do you get if you multiply your final horizontal position by your final depth?_
|
||||
|
||||
### Part Two
|
||||
|
||||
Based on your calculations, the planned course doesn't seem to make any sense. You find the submarine manual and discover that the process is actually slightly more complicated.
|
||||
|
||||
In addition to horizontal position and depth, you'll also need to track a third value, _aim_, which also starts at `0`. The commands also mean something entirely different than you first thought:
|
||||
|
||||
* `down X` _increases_ your aim by `X` units.
|
||||
* `up X` _decreases_ your aim by `X` units.
|
||||
* `forward X` does two things:
|
||||
* It increases your horizontal position by `X` units.
|
||||
* It increases your depth by your aim _multiplied by_ `X`.
|
||||
|
||||
Again note that since you're on a submarine, `down` and `up` do the opposite of what you might expect: "down" means aiming in the positive direction.
|
||||
|
||||
Now, the above example does something different:
|
||||
|
||||
* `forward 5` adds `5` to your horizontal position, a total of `5`. Because your aim is `0`, your depth does not change.
|
||||
* `down 5` adds `5` to your aim, resulting in a value of `5`.
|
||||
* `forward 8` adds `8` to your horizontal position, a total of `13`. Because your aim is `5`, your depth increases by `8*5=40`.
|
||||
* `up 3` decreases your aim by `3`, resulting in a value of `2`.
|
||||
* `down 8` adds `8` to your aim, resulting in a value of `10`.
|
||||
* `forward 2` adds `2` to your horizontal position, a total of `15`. Because your aim is `10`, your depth increases by `2*10=20` to a total of `60`.
|
||||
|
||||
After following these new instructions, you would have a horizontal position of `15` and a depth of `60`. (Multiplying these produces _`900`_.)
|
||||
|
||||
Using this new interpretation of the commands, calculate the horizontal position and depth you would have after following the planned course. _What do you get if you multiply your final horizontal position by your final depth?_
|
1000
data/Y21/day3/data.txt
Normal file
1000
data/Y21/day3/data.txt
Normal file
File diff suppressed because it is too large
Load Diff
12
data/Y21/day3/example.txt
Normal file
12
data/Y21/day3/example.txt
Normal file
@ -0,0 +1,12 @@
|
||||
00100
|
||||
11110
|
||||
10110
|
||||
10111
|
||||
10101
|
||||
01111
|
||||
00111
|
||||
11100
|
||||
10000
|
||||
11001
|
||||
00010
|
||||
01010
|
76
data/Y21/day3/puzzle.md
Normal file
76
data/Y21/day3/puzzle.md
Normal file
@ -0,0 +1,76 @@
|
||||
# Day 3: Binary Diagnostic
|
||||
|
||||
[https://adventofcode.com/2021/day/3](https://adventofcode.com/2021/day/3)
|
||||
|
||||
## Description
|
||||
|
||||
### Part One
|
||||
|
||||
The submarine has been making some <span title="Turns out oceans are heavy.">odd creaking noises</span>, so you ask it to produce a diagnostic report just in case.
|
||||
|
||||
The diagnostic report (your puzzle input) consists of a list of binary numbers which, when decoded properly, can tell you many useful things about the conditions of the submarine. The first parameter to check is the _power consumption_.
|
||||
|
||||
You need to use the binary numbers in the diagnostic report to generate two new binary numbers (called the _gamma rate_ and the _epsilon rate_). The power consumption can then be found by multiplying the gamma rate by the epsilon rate.
|
||||
|
||||
Each bit in the gamma rate can be determined by finding the _most common bit in the corresponding position_ of all numbers in the diagnostic report. For example, given the following diagnostic report:
|
||||
|
||||
00100
|
||||
11110
|
||||
10110
|
||||
10111
|
||||
10101
|
||||
01111
|
||||
00111
|
||||
11100
|
||||
10000
|
||||
11001
|
||||
00010
|
||||
01010
|
||||
|
||||
|
||||
Considering only the first bit of each number, there are five `0` bits and seven `1` bits. Since the most common bit is `1`, the first bit of the gamma rate is `1`.
|
||||
|
||||
The most common second bit of the numbers in the diagnostic report is `0`, so the second bit of the gamma rate is `0`.
|
||||
|
||||
The most common value of the third, fourth, and fifth bits are `1`, `1`, and `0`, respectively, and so the final three bits of the gamma rate are `110`.
|
||||
|
||||
So, the gamma rate is the binary number `10110`, or _`22`_ in decimal.
|
||||
|
||||
The epsilon rate is calculated in a similar way; rather than use the most common bit, the least common bit from each position is used. So, the epsilon rate is `01001`, or _`9`_ in decimal. Multiplying the gamma rate (`22`) by the epsilon rate (`9`) produces the power consumption, _`198`_.
|
||||
|
||||
Use the binary numbers in your diagnostic report to calculate the gamma rate and epsilon rate, then multiply them together. _What is the power consumption of the submarine?_ (Be sure to represent your answer in decimal, not binary.)
|
||||
|
||||
### Part Two
|
||||
|
||||
Next, you should verify the _life support rating_, which can be determined by multiplying the _oxygen generator rating_ by the _CO2 scrubber rating_.
|
||||
|
||||
Both the oxygen generator rating and the CO2 scrubber rating are values that can be found in your diagnostic report - finding them is the tricky part. Both values are located using a similar process that involves filtering out values until only one remains. Before searching for either rating value, start with the full list of binary numbers from your diagnostic report and _consider just the first bit_ of those numbers. Then:
|
||||
|
||||
* Keep only numbers selected by the _bit criteria_ for the type of rating value for which you are searching. Discard numbers which do not match the bit criteria.
|
||||
* If you only have one number left, stop; this is the rating value for which you are searching.
|
||||
* Otherwise, repeat the process, considering the next bit to the right.
|
||||
|
||||
The _bit criteria_ depends on which type of rating value you want to find:
|
||||
|
||||
* To find _oxygen generator rating_, determine the _most common_ value (`0` or `1`) in the current bit position, and keep only numbers with that bit in that position. If `0` and `1` are equally common, keep values with a _`1`_ in the position being considered.
|
||||
* To find _CO2 scrubber rating_, determine the _least common_ value (`0` or `1`) in the current bit position, and keep only numbers with that bit in that position. If `0` and `1` are equally common, keep values with a _`0`_ in the position being considered.
|
||||
|
||||
For example, to determine the _oxygen generator rating_ value using the same example diagnostic report from above:
|
||||
|
||||
* Start with all 12 numbers and consider only the first bit of each number. There are more `1` bits (7) than `0` bits (5), so keep only the 7 numbers with a `1` in the first position: `11110`, `10110`, `10111`, `10101`, `11100`, `10000`, and `11001`.
|
||||
* Then, consider the second bit of the 7 remaining numbers: there are more `0` bits (4) than `1` bits (3), so keep only the 4 numbers with a `0` in the second position: `10110`, `10111`, `10101`, and `10000`.
|
||||
* In the third position, three of the four numbers have a `1`, so keep those three: `10110`, `10111`, and `10101`.
|
||||
* In the fourth position, two of the three numbers have a `1`, so keep those two: `10110` and `10111`.
|
||||
* In the fifth position, there are an equal number of `0` bits and `1` bits (one each). So, to find the _oxygen generator rating_, keep the number with a `1` in that position: `10111`.
|
||||
* As there is only one number left, stop; the _oxygen generator rating_ is `10111`, or _`23`_ in decimal.
|
||||
|
||||
Then, to determine the _CO2 scrubber rating_ value from the same example above:
|
||||
|
||||
* Start again with all 12 numbers and consider only the first bit of each number. There are fewer `0` bits (5) than `1` bits (7), so keep only the 5 numbers with a `0` in the first position: `00100`, `01111`, `00111`, `00010`, and `01010`.
|
||||
* Then, consider the second bit of the 5 remaining numbers: there are fewer `1` bits (2) than `0` bits (3), so keep only the 2 numbers with a `1` in the second position: `01111` and `01010`.
|
||||
* In the third position, there are an equal number of `0` bits and `1` bits (one each). So, to find the _CO2 scrubber rating_, keep the number with a `0` in that position: `01010`.
|
||||
* As there is only one number left, stop; the _CO2 scrubber rating_ is `01010`, or _`10`_ in decimal.
|
||||
|
||||
Finally, to find the life support rating, multiply the oxygen generator rating (`23`) by the CO2 scrubber rating (`10`) to get _`230`_.
|
||||
|
||||
Use the binary numbers in your diagnostic report to calculate the oxygen generator rating and CO2 scrubber rating, then multiply them together. _What is the life support rating of the submarine?_ (Be sure to represent your answer in decimal, not binary.)
|
601
data/Y21/day4/data.txt
Normal file
601
data/Y21/day4/data.txt
Normal file
@ -0,0 +1,601 @@
|
||||
91,17,64,45,8,13,47,19,52,68,63,76,82,44,28,56,37,2,78,48,32,58,72,53,9,85,77,89,36,22,49,86,51,99,6,92,80,87,7,25,31,66,84,4,98,67,46,61,59,79,0,3,38,27,23,95,20,35,14,30,26,33,42,93,12,57,11,54,50,75,90,41,88,96,40,81,24,94,18,39,70,34,21,55,5,29,71,83,1,60,74,69,10,62,43,73,97,65,15,16
|
||||
|
||||
83 40 67 98 4
|
||||
50 74 31 30 3
|
||||
75 64 79 61 5
|
||||
12 59 26 25 72
|
||||
36 33 18 54 10
|
||||
|
||||
68 56 28 57 12
|
||||
78 66 20 85 51
|
||||
35 23 7 99 44
|
||||
86 37 8 45 49
|
||||
40 77 32 6 88
|
||||
|
||||
75 15 20 79 8
|
||||
81 69 54 33 28
|
||||
9 53 48 95 27
|
||||
65 84 40 71 36
|
||||
13 31 6 68 29
|
||||
|
||||
94 6 30 16 74
|
||||
91 47 66 31 90
|
||||
14 56 45 55 20
|
||||
58 70 27 46 73
|
||||
77 67 97 51 54
|
||||
|
||||
60 12 49 80 52
|
||||
15 27 85 82 48
|
||||
21 76 83 55 54
|
||||
8 5 4 38 47
|
||||
73 2 86 44 99
|
||||
|
||||
64 60 6 38 37
|
||||
3 69 21 24 11
|
||||
36 88 16 55 41
|
||||
78 7 81 95 91
|
||||
27 34 92 39 30
|
||||
|
||||
38 57 20 68 49
|
||||
21 18 69 97 60
|
||||
34 92 0 59 62
|
||||
10 43 93 87 64
|
||||
53 35 94 76 61
|
||||
|
||||
48 74 58 13 54
|
||||
57 18 37 92 78
|
||||
89 10 25 97 43
|
||||
38 99 64 6 66
|
||||
21 83 29 93 95
|
||||
|
||||
94 37 98 87 51
|
||||
50 65 77 83 95
|
||||
68 4 91 53 32
|
||||
56 26 15 2 80
|
||||
20 55 58 81 33
|
||||
|
||||
73 32 66 38 89
|
||||
18 79 40 78 55
|
||||
26 63 93 60 98
|
||||
42 65 96 47 57
|
||||
45 75 72 23 35
|
||||
|
||||
64 28 21 80 27
|
||||
93 58 71 67 11
|
||||
61 20 74 13 90
|
||||
76 35 46 94 40
|
||||
92 2 4 85 69
|
||||
|
||||
22 70 87 31 61
|
||||
74 78 58 4 90
|
||||
63 28 24 35 84
|
||||
59 8 89 88 47
|
||||
17 48 80 33 32
|
||||
|
||||
57 7 30 39 19
|
||||
1 13 41 15 50
|
||||
44 72 2 5 70
|
||||
34 93 60 80 69
|
||||
49 14 25 10 33
|
||||
|
||||
45 41 77 89 27
|
||||
68 99 11 32 95
|
||||
15 4 72 98 52
|
||||
53 28 14 75 44
|
||||
57 9 62 92 69
|
||||
|
||||
7 21 2 73 40
|
||||
52 60 57 53 65
|
||||
63 86 36 82 44
|
||||
14 28 39 12 80
|
||||
66 64 91 50 51
|
||||
|
||||
82 5 38 41 95
|
||||
70 52 11 21 51
|
||||
81 20 0 14 83
|
||||
57 36 60 59 42
|
||||
77 13 85 32 63
|
||||
|
||||
91 40 42 3 50
|
||||
22 24 81 31 93
|
||||
9 79 82 43 89
|
||||
6 77 76 26 37
|
||||
29 8 53 23 4
|
||||
|
||||
7 78 32 44 74
|
||||
29 3 84 38 79
|
||||
58 41 87 88 30
|
||||
68 19 72 81 47
|
||||
15 63 52 6 26
|
||||
|
||||
20 41 92 84 25
|
||||
9 4 96 85 66
|
||||
49 15 50 89 19
|
||||
48 45 82 86 60
|
||||
29 18 53 47 16
|
||||
|
||||
75 39 45 31 73
|
||||
91 86 69 94 66
|
||||
28 61 17 20 0
|
||||
88 21 89 41 37
|
||||
35 2 10 18 82
|
||||
|
||||
80 23 4 73 93
|
||||
89 8 20 12 45
|
||||
74 99 58 90 67
|
||||
50 85 35 88 55
|
||||
18 65 42 47 48
|
||||
|
||||
16 38 65 64 25
|
||||
20 74 37 15 82
|
||||
23 76 97 48 53
|
||||
60 93 85 1 35
|
||||
77 10 59 2 58
|
||||
|
||||
11 9 57 40 46
|
||||
35 88 29 52 17
|
||||
30 2 7 6 0
|
||||
13 63 44 68 59
|
||||
83 98 5 50 65
|
||||
|
||||
82 40 2 14 50
|
||||
7 31 91 19 11
|
||||
51 42 56 44 6
|
||||
66 74 22 95 64
|
||||
63 1 17 86 24
|
||||
|
||||
18 19 66 63 80
|
||||
65 23 74 22 85
|
||||
5 7 37 75 51
|
||||
38 58 68 83 32
|
||||
40 29 31 15 43
|
||||
|
||||
37 54 13 77 31
|
||||
57 96 28 87 95
|
||||
10 11 19 49 45
|
||||
12 21 79 56 24
|
||||
34 64 84 69 17
|
||||
|
||||
6 33 48 61 0
|
||||
85 34 7 84 37
|
||||
25 46 59 76 82
|
||||
18 62 20 44 2
|
||||
12 78 60 56 99
|
||||
|
||||
95 6 1 39 2
|
||||
46 34 28 64 22
|
||||
48 23 89 56 55
|
||||
44 81 82 43 74
|
||||
65 31 94 49 91
|
||||
|
||||
69 42 27 52 54
|
||||
79 60 62 83 38
|
||||
5 21 56 48 99
|
||||
51 40 15 7 24
|
||||
92 10 66 64 88
|
||||
|
||||
99 18 22 52 81
|
||||
21 42 13 71 59
|
||||
91 38 68 10 25
|
||||
54 19 76 60 24
|
||||
41 92 2 3 64
|
||||
|
||||
76 5 25 55 84
|
||||
70 15 89 67 68
|
||||
34 86 11 4 6
|
||||
9 23 43 41 52
|
||||
58 10 88 38 0
|
||||
|
||||
83 91 85 81 86
|
||||
5 10 89 6 48
|
||||
45 77 2 9 90
|
||||
74 8 57 75 67
|
||||
73 30 49 96 15
|
||||
|
||||
66 13 82 89 20
|
||||
5 67 94 64 0
|
||||
58 73 4 62 49
|
||||
59 28 75 79 44
|
||||
54 71 57 33 36
|
||||
|
||||
23 36 29 80 30
|
||||
51 91 77 2 84
|
||||
78 90 15 21 75
|
||||
28 93 22 55 16
|
||||
67 50 58 60 68
|
||||
|
||||
82 80 37 91 7
|
||||
54 81 85 25 24
|
||||
33 36 89 30 56
|
||||
83 95 99 48 10
|
||||
4 44 1 55 79
|
||||
|
||||
9 13 53 20 26
|
||||
7 31 49 84 58
|
||||
51 91 90 68 55
|
||||
19 38 23 81 33
|
||||
34 99 85 37 54
|
||||
|
||||
44 66 81 78 15
|
||||
31 14 48 65 0
|
||||
26 10 20 4 41
|
||||
77 68 95 34 73
|
||||
74 12 36 3 60
|
||||
|
||||
6 24 78 58 36
|
||||
30 51 75 13 40
|
||||
17 1 3 42 59
|
||||
64 20 4 18 79
|
||||
37 61 84 63 7
|
||||
|
||||
41 83 1 75 18
|
||||
14 56 67 32 22
|
||||
69 80 46 84 49
|
||||
72 21 9 10 35
|
||||
4 37 28 40 12
|
||||
|
||||
56 80 47 17 70
|
||||
12 22 77 81 11
|
||||
61 30 58 60 71
|
||||
52 0 25 86 65
|
||||
59 28 79 20 26
|
||||
|
||||
70 75 81 18 67
|
||||
2 85 73 8 17
|
||||
74 3 34 92 30
|
||||
51 72 84 56 45
|
||||
37 90 31 97 78
|
||||
|
||||
2 73 71 43 69
|
||||
6 54 89 57 93
|
||||
81 0 39 25 90
|
||||
79 27 92 29 15
|
||||
45 76 87 11 91
|
||||
|
||||
98 35 51 49 34
|
||||
23 12 77 27 82
|
||||
6 89 0 76 46
|
||||
81 48 99 45 90
|
||||
10 75 17 96 29
|
||||
|
||||
45 19 82 93 0
|
||||
84 24 73 2 98
|
||||
94 46 7 48 56
|
||||
80 34 5 18 31
|
||||
58 33 83 29 55
|
||||
|
||||
66 81 99 54 63
|
||||
21 94 72 77 64
|
||||
58 52 85 46 68
|
||||
5 6 78 42 4
|
||||
76 38 51 24 33
|
||||
|
||||
93 26 5 59 67
|
||||
13 84 76 4 69
|
||||
0 17 30 83 48
|
||||
8 53 32 14 92
|
||||
94 18 66 46 61
|
||||
|
||||
28 48 38 6 25
|
||||
70 39 71 77 22
|
||||
66 94 18 43 36
|
||||
30 67 57 9 90
|
||||
15 34 50 3 86
|
||||
|
||||
11 90 99 92 87
|
||||
78 79 56 21 50
|
||||
19 18 22 20 30
|
||||
95 41 59 85 26
|
||||
66 58 46 38 57
|
||||
|
||||
49 92 2 93 77
|
||||
46 89 44 57 19
|
||||
53 8 32 18 88
|
||||
54 95 59 70 10
|
||||
72 84 86 42 81
|
||||
|
||||
44 78 25 4 57
|
||||
72 7 42 94 8
|
||||
61 79 11 29 59
|
||||
22 82 6 90 12
|
||||
98 77 5 68 50
|
||||
|
||||
48 41 64 15 57
|
||||
76 7 52 53 93
|
||||
70 84 94 38 35
|
||||
47 18 13 51 21
|
||||
77 62 63 3 65
|
||||
|
||||
31 33 48 79 69
|
||||
30 9 83 53 50
|
||||
60 94 36 2 28
|
||||
59 19 10 5 40
|
||||
26 41 72 14 96
|
||||
|
||||
0 16 49 75 17
|
||||
28 20 21 99 94
|
||||
15 8 4 68 71
|
||||
23 53 76 19 74
|
||||
79 61 72 70 52
|
||||
|
||||
70 89 12 80 76
|
||||
14 18 16 4 91
|
||||
34 64 43 51 71
|
||||
6 78 30 5 13
|
||||
57 42 15 73 24
|
||||
|
||||
64 99 72 41 54
|
||||
21 29 25 40 9
|
||||
92 48 82 70 98
|
||||
65 62 8 78 27
|
||||
71 86 36 34 23
|
||||
|
||||
23 19 72 77 63
|
||||
85 0 61 40 14
|
||||
69 76 18 56 95
|
||||
68 66 28 79 13
|
||||
83 84 45 89 2
|
||||
|
||||
18 40 28 70 37
|
||||
80 30 67 96 34
|
||||
77 25 97 32 11
|
||||
48 46 89 14 29
|
||||
2 8 95 0 12
|
||||
|
||||
0 26 1 9 30
|
||||
17 2 78 18 65
|
||||
84 7 61 93 81
|
||||
80 44 82 23 99
|
||||
72 95 19 60 28
|
||||
|
||||
37 39 0 20 21
|
||||
91 36 93 16 22
|
||||
53 95 26 72 25
|
||||
97 33 60 55 65
|
||||
79 56 73 29 75
|
||||
|
||||
22 58 99 57 28
|
||||
2 56 93 91 18
|
||||
44 64 92 85 46
|
||||
70 47 89 27 54
|
||||
83 5 48 97 72
|
||||
|
||||
72 1 73 68 36
|
||||
31 8 14 41 35
|
||||
23 96 7 92 83
|
||||
56 39 77 93 91
|
||||
20 28 67 10 11
|
||||
|
||||
62 27 17 54 0
|
||||
35 60 73 20 5
|
||||
23 58 46 99 75
|
||||
19 53 79 70 88
|
||||
31 85 77 1 32
|
||||
|
||||
22 90 81 42 55
|
||||
70 78 86 19 94
|
||||
1 43 15 33 51
|
||||
84 96 87 58 6
|
||||
49 64 4 59 23
|
||||
|
||||
82 63 58 75 89
|
||||
35 37 52 80 24
|
||||
93 50 76 79 1
|
||||
86 59 30 92 7
|
||||
42 11 55 70 22
|
||||
|
||||
83 3 71 28 95
|
||||
70 23 68 57 1
|
||||
60 6 19 63 32
|
||||
64 55 97 81 49
|
||||
91 80 88 5 35
|
||||
|
||||
23 68 51 62 20
|
||||
70 52 98 34 41
|
||||
12 21 85 43 84
|
||||
69 49 36 28 0
|
||||
76 30 58 91 60
|
||||
|
||||
30 72 6 41 43
|
||||
67 79 46 96 99
|
||||
58 71 39 87 69
|
||||
17 18 11 57 25
|
||||
45 75 16 33 42
|
||||
|
||||
22 75 24 74 90
|
||||
34 70 44 86 23
|
||||
29 59 68 4 48
|
||||
88 45 92 27 49
|
||||
47 77 26 99 82
|
||||
|
||||
42 29 21 74 33
|
||||
64 37 38 50 84
|
||||
46 44 41 1 67
|
||||
53 66 96 68 59
|
||||
6 94 11 31 99
|
||||
|
||||
24 32 71 87 57
|
||||
42 26 55 80 99
|
||||
82 27 16 19 92
|
||||
96 48 62 31 61
|
||||
60 89 95 18 6
|
||||
|
||||
99 33 55 71 29
|
||||
75 37 23 27 98
|
||||
2 78 90 18 35
|
||||
59 10 56 0 6
|
||||
12 19 76 70 96
|
||||
|
||||
33 37 23 61 80
|
||||
6 13 68 51 76
|
||||
92 25 3 95 55
|
||||
99 63 17 52 30
|
||||
11 94 42 5 98
|
||||
|
||||
77 37 25 14 73
|
||||
95 90 10 19 72
|
||||
78 30 44 47 91
|
||||
3 60 32 5 66
|
||||
21 55 87 98 6
|
||||
|
||||
6 60 82 90 98
|
||||
21 70 54 66 27
|
||||
37 64 55 10 14
|
||||
57 25 84 50 20
|
||||
42 59 85 3 73
|
||||
|
||||
74 84 92 10 51
|
||||
57 82 93 90 44
|
||||
41 43 76 48 59
|
||||
79 49 69 16 72
|
||||
37 29 63 15 68
|
||||
|
||||
37 90 97 86 18
|
||||
2 83 30 53 92
|
||||
45 35 78 47 40
|
||||
67 61 17 14 84
|
||||
32 33 81 10 11
|
||||
|
||||
46 48 39 3 50
|
||||
83 29 91 73 67
|
||||
25 43 89 71 36
|
||||
63 62 78 95 18
|
||||
82 34 23 85 11
|
||||
|
||||
19 68 80 50 13
|
||||
1 45 51 27 39
|
||||
98 26 24 46 49
|
||||
14 92 63 88 66
|
||||
15 44 84 47 94
|
||||
|
||||
19 39 93 43 86
|
||||
91 58 3 69 41
|
||||
18 36 95 52 83
|
||||
12 6 22 48 0
|
||||
25 70 40 88 73
|
||||
|
||||
95 11 94 13 14
|
||||
64 87 57 98 49
|
||||
47 88 84 61 2
|
||||
46 21 15 74 59
|
||||
82 73 78 3 51
|
||||
|
||||
18 72 29 7 36
|
||||
96 67 81 78 23
|
||||
43 40 44 47 98
|
||||
41 26 15 90 71
|
||||
42 62 93 70 2
|
||||
|
||||
17 8 59 25 33
|
||||
81 47 55 99 48
|
||||
86 14 71 54 50
|
||||
90 11 23 18 0
|
||||
97 65 82 68 42
|
||||
|
||||
50 54 68 90 83
|
||||
10 28 77 55 61
|
||||
38 60 52 80 44
|
||||
40 81 14 24 87
|
||||
51 82 42 30 8
|
||||
|
||||
54 5 64 22 60
|
||||
70 19 83 11 45
|
||||
46 39 2 56 6
|
||||
61 8 28 20 94
|
||||
0 4 81 34 84
|
||||
|
||||
96 21 48 89 15
|
||||
91 40 9 97 65
|
||||
26 58 10 18 78
|
||||
98 79 29 80 28
|
||||
17 59 43 84 99
|
||||
|
||||
67 73 21 9 31
|
||||
68 37 26 65 84
|
||||
63 24 42 27 40
|
||||
61 25 30 34 35
|
||||
53 23 48 81 29
|
||||
|
||||
24 34 5 67 62
|
||||
89 85 68 37 78
|
||||
42 87 13 49 41
|
||||
74 55 70 86 76
|
||||
73 94 97 63 48
|
||||
|
||||
88 24 6 75 30
|
||||
77 64 16 34 93
|
||||
36 76 0 40 81
|
||||
67 14 89 84 95
|
||||
32 19 18 66 9
|
||||
|
||||
97 71 65 30 69
|
||||
41 21 40 31 33
|
||||
50 55 35 52 53
|
||||
4 51 13 81 72
|
||||
12 83 14 64 18
|
||||
|
||||
97 7 8 74 10
|
||||
3 92 31 25 41
|
||||
20 32 45 72 55
|
||||
1 43 49 98 27
|
||||
99 54 57 13 76
|
||||
|
||||
86 81 67 6 97
|
||||
34 18 96 43 56
|
||||
59 75 17 26 9
|
||||
0 38 60 94 14
|
||||
4 55 64 61 88
|
||||
|
||||
37 15 48 43 66
|
||||
45 54 90 81 47
|
||||
63 64 28 82 93
|
||||
34 52 6 99 61
|
||||
49 12 71 23 46
|
||||
|
||||
90 87 89 97 1
|
||||
48 0 82 60 43
|
||||
55 30 68 25 83
|
||||
78 3 23 16 66
|
||||
98 2 19 63 17
|
||||
|
||||
89 52 49 14 38
|
||||
69 12 50 17 90
|
||||
58 53 26 20 29
|
||||
39 65 43 7 5
|
||||
84 68 94 85 25
|
||||
|
||||
95 25 42 36 47
|
||||
50 54 83 84 37
|
||||
94 70 99 79 18
|
||||
57 8 69 52 31
|
||||
66 20 35 71 38
|
||||
|
||||
81 18 47 68 15
|
||||
3 50 16 83 37
|
||||
34 31 9 57 76
|
||||
74 95 40 63 48
|
||||
13 28 20 43 66
|
||||
|
||||
52 21 62 41 67
|
||||
22 56 36 18 23
|
||||
59 44 27 73 3
|
||||
72 50 19 33 76
|
||||
45 55 70 46 92
|
||||
|
||||
72 96 50 83 68
|
||||
31 78 59 57 93
|
||||
43 58 17 52 35
|
||||
87 34 91 76 0
|
||||
54 75 53 25 62
|
||||
|
||||
21 53 68 5 80
|
||||
47 67 6 81 9
|
||||
64 46 35 26 39
|
||||
50 24 84 45 71
|
||||
66 15 83 3 97
|
||||
|
||||
22 97 31 90 63
|
||||
21 51 38 74 78
|
||||
10 64 92 82 1
|
||||
70 12 75 16 14
|
||||
68 50 35 73 26
|
19
data/Y21/day4/example.txt
Normal file
19
data/Y21/day4/example.txt
Normal file
@ -0,0 +1,19 @@
|
||||
7,4,9,5,11,17,23,2,0,14,21,24,10,16,13,6,15,25,12,22,18,20,8,19,3,26,1
|
||||
|
||||
22 13 17 11 0
|
||||
8 2 23 4 24
|
||||
21 9 14 16 7
|
||||
6 10 3 18 5
|
||||
1 12 20 15 19
|
||||
|
||||
3 15 0 2 22
|
||||
9 18 13 17 5
|
||||
19 8 7 25 23
|
||||
20 11 10 24 4
|
||||
14 21 16 12 6
|
||||
|
||||
14 21 17 24 4
|
||||
10 16 15 9 19
|
||||
18 8 23 26 20
|
||||
22 11 13 6 5
|
||||
2 0 12 3 7
|
79
data/Y21/day4/puzzle.md
Normal file
79
data/Y21/day4/puzzle.md
Normal file
@ -0,0 +1,79 @@
|
||||
# Day 4: Giant Squid
|
||||
|
||||
[https://adventofcode.com/2021/day/4](https://adventofcode.com/2021/day/4)
|
||||
|
||||
## Description
|
||||
|
||||
### Part One
|
||||
|
||||
You're already almost 1.5km (almost a mile) below the surface of the ocean, already so deep that you can't see any sunlight. What you _can_ see, however, is a giant squid that has attached itself to the outside of your submarine.
|
||||
|
||||
Maybe it wants to play [bingo](https://en.wikipedia.org/wiki/Bingo_(American_version))?
|
||||
|
||||
Bingo is played on a set of boards each consisting of a 5x5 grid of numbers. Numbers are chosen at random, and the chosen number is _marked_ on all boards on which it appears. (Numbers may not appear on all boards.) If all numbers in any row or any column of a board are marked, that board _wins_. (Diagonals don't count.)
|
||||
|
||||
The submarine has a _bingo subsystem_ to help passengers (currently, you and the giant squid) pass the time. It automatically generates a random order in which to draw numbers and a random set of boards (your puzzle input). For example:
|
||||
|
||||
7,4,9,5,11,17,23,2,0,14,21,24,10,16,13,6,15,25,12,22,18,20,8,19,3,26,1
|
||||
|
||||
22 13 17 11 0
|
||||
8 2 23 4 24
|
||||
21 9 14 16 7
|
||||
6 10 3 18 5
|
||||
1 12 20 15 19
|
||||
|
||||
3 15 0 2 22
|
||||
9 18 13 17 5
|
||||
19 8 7 25 23
|
||||
20 11 10 24 4
|
||||
14 21 16 12 6
|
||||
|
||||
14 21 17 24 4
|
||||
10 16 15 9 19
|
||||
18 8 23 26 20
|
||||
22 11 13 6 5
|
||||
2 0 12 3 7
|
||||
|
||||
|
||||
After the first five numbers are drawn (`7`, `4`, `9`, `5`, and `11`), there are no winners, but the boards are marked as follows (shown here adjacent to each other to save space):
|
||||
|
||||
22 13 17 11 0 3 15 0 2 22 14 21 17 24 4
|
||||
8 2 23 4 24 9 18 13 17 5 10 16 15 9 19
|
||||
21 9 14 16 7 19 8 7 25 23 18 8 23 26 20
|
||||
6 10 3 18 5 20 11 10 24 4 22 11 13 6 5
|
||||
1 12 20 15 19 14 21 16 12 6 2 0 12 3 7
|
||||
|
||||
|
||||
After the next six numbers are drawn (`17`, `23`, `2`, `0`, `14`, and `21`), there are still no winners:
|
||||
|
||||
22 13 17 11 0 3 15 0 2 22 14 21 17 24 4
|
||||
8 2 23 4 24 9 18 13 17 5 10 16 15 9 19
|
||||
21 9 14 16 7 19 8 7 25 23 18 8 23 26 20
|
||||
6 10 3 18 5 20 11 10 24 4 22 11 13 6 5
|
||||
1 12 20 15 19 14 21 16 12 6 2 0 12 3 7
|
||||
|
||||
|
||||
Finally, `24` is drawn:
|
||||
|
||||
22 13 17 11 0 3 15 0 2 22 14 21 17 24 4
|
||||
8 2 23 4 24 9 18 13 17 5 10 16 15 9 19
|
||||
21 9 14 16 7 19 8 7 25 23 18 8 23 26 20
|
||||
6 10 3 18 5 20 11 10 24 4 22 11 13 6 5
|
||||
1 12 20 15 19 14 21 16 12 6 2 0 12 3 7
|
||||
|
||||
|
||||
At this point, the third board _wins_ because it has at least one complete row or column of marked numbers (in this case, the entire top row is marked: _`14 21 17 24 4`_).
|
||||
|
||||
The _score_ of the winning board can now be calculated. Start by finding the _sum of all unmarked numbers_ on that board; in this case, the sum is `188`. Then, multiply that sum by _the number that was just called_ when the board won, `24`, to get the final score, `188 * 24 = 4512`.
|
||||
|
||||
To guarantee victory against the giant squid, figure out which board will win first. _What will your final score be if you choose that board?_
|
||||
|
||||
### Part Two
|
||||
|
||||
On the other hand, it might be wise to try a different strategy: <span title="That's 'cuz a submarine don't pull things' antennas out of their sockets when they lose. Giant squid are known to do that.">let the giant squid win</span>.
|
||||
|
||||
You aren't sure how many bingo boards a giant squid could play at once, so rather than waste time counting its arms, the safe thing to do is to _figure out which board will win last_ and choose that one. That way, no matter which boards it picks, it will win for sure.
|
||||
|
||||
In the above example, the second board is the last to win, which happens after `13` is eventually called and its middle column is completely marked. If you were to keep playing until this point, the second board would have a sum of unmarked numbers equal to `148` for a final score of `148 * 13 = 1924`.
|
||||
|
||||
Figure out which board will win last. _Once it wins, what would its final score be?_
|
1
data/Y21/day6/data.txt
Normal file
1
data/Y21/day6/data.txt
Normal file
@ -0,0 +1 @@
|
||||
5,4,3,5,1,1,2,1,2,1,3,2,3,4,5,1,2,4,3,2,5,1,4,2,1,1,2,5,4,4,4,1,5,4,5,2,1,2,5,5,4,1,3,1,4,2,4,2,5,1,3,5,3,2,3,1,1,4,5,2,4,3,1,5,5,1,3,1,3,2,2,4,1,3,4,3,3,4,1,3,4,3,4,5,2,1,1,1,4,5,5,1,1,3,2,4,1,2,2,2,4,1,2,5,5,1,4,5,2,4,2,1,5,4,1,3,4,1,2,3,1,5,1,3,4,5,4,1,4,3,3,3,5,5,1,1,5,1,5,5,1,5,2,1,5,1,2,3,5,5,1,3,3,1,5,3,4,3,4,3,2,5,2,1,2,5,1,1,1,1,5,1,1,4,3,3,5,1,1,1,4,4,1,3,3,5,5,4,3,2,1,2,2,3,4,1,5,4,3,1,1,5,1,4,2,3,2,2,3,4,1,3,4,1,4,3,4,3,1,3,3,1,1,4,1,1,1,4,5,3,1,1,2,5,2,5,1,5,3,3,1,3,5,5,1,5,4,3,1,5,1,1,5,5,1,1,2,5,5,5,1,1,3,2,2,3,4,5,5,2,5,4,2,1,5,1,4,4,5,4,4,1,2,1,1,2,3,5,5,1,3,1,4,2,3,3,1,4,1,1
|
1
data/Y21/day6/example.txt
Normal file
1
data/Y21/day6/example.txt
Normal file
@ -0,0 +1 @@
|
||||
3,4,3,1,2
|
68
data/Y21/day6/puzzle.md
Normal file
68
data/Y21/day6/puzzle.md
Normal file
@ -0,0 +1,68 @@
|
||||
# Day 6: Lanternfish
|
||||
|
||||
[https://adventofcode.com/2021/day/6](https://adventofcode.com/2021/day/6)
|
||||
|
||||
## Description
|
||||
|
||||
### Part One
|
||||
|
||||
The sea floor is getting steeper. Maybe the sleigh keys got carried this way?
|
||||
|
||||
A massive school of glowing [lanternfish](https://en.wikipedia.org/wiki/Lanternfish) swims past. They must spawn quickly to reach such large numbers - maybe _exponentially_ quickly? You should model their growth rate to be sure.
|
||||
|
||||
Although you know nothing about this specific species of lanternfish, you make some guesses about their attributes. Surely, <span title="I heard you like lanternfish.">each lanternfish creates a new lanternfish</span> once every _7_ days.
|
||||
|
||||
However, this process isn't necessarily synchronized between every lanternfish - one lanternfish might have 2 days left until it creates another lanternfish, while another might have 4. So, you can model each fish as a single number that represents _the number of days until it creates a new lanternfish_.
|
||||
|
||||
Furthermore, you reason, a _new_ lanternfish would surely need slightly longer before it's capable of producing more lanternfish: two more days for its first cycle.
|
||||
|
||||
So, suppose you have a lanternfish with an internal timer value of `3`:
|
||||
|
||||
* After one day, its internal timer would become `2`.
|
||||
* After another day, its internal timer would become `1`.
|
||||
* After another day, its internal timer would become `0`.
|
||||
* After another day, its internal timer would reset to `6`, and it would create a _new_ lanternfish with an internal timer of `8`.
|
||||
* After another day, the first lanternfish would have an internal timer of `5`, and the second lanternfish would have an internal timer of `7`.
|
||||
|
||||
A lanternfish that creates a new fish resets its timer to `6`, _not `7`_ (because `0` is included as a valid timer value). The new lanternfish starts with an internal timer of `8` and does not start counting down until the next day.
|
||||
|
||||
Realizing what you're trying to do, the submarine automatically produces a list of the ages of several hundred nearby lanternfish (your puzzle input). For example, suppose you were given the following list:
|
||||
|
||||
3,4,3,1,2
|
||||
|
||||
This list means that the first fish has an internal timer of `3`, the second fish has an internal timer of `4`, and so on until the fifth fish, which has an internal timer of `2`. Simulating these fish over several days would proceed as follows:
|
||||
|
||||
Initial state: 3,4,3,1,2
|
||||
After 1 day: 2,3,2,0,1
|
||||
After 2 days: 1,2,1,6,0,8
|
||||
After 3 days: 0,1,0,5,6,7,8
|
||||
After 4 days: 6,0,6,4,5,6,7,8,8
|
||||
After 5 days: 5,6,5,3,4,5,6,7,7,8
|
||||
After 6 days: 4,5,4,2,3,4,5,6,6,7
|
||||
After 7 days: 3,4,3,1,2,3,4,5,5,6
|
||||
After 8 days: 2,3,2,0,1,2,3,4,4,5
|
||||
After 9 days: 1,2,1,6,0,1,2,3,3,4,8
|
||||
After 10 days: 0,1,0,5,6,0,1,2,2,3,7,8
|
||||
After 11 days: 6,0,6,4,5,6,0,1,1,2,6,7,8,8,8
|
||||
After 12 days: 5,6,5,3,4,5,6,0,0,1,5,6,7,7,7,8,8
|
||||
After 13 days: 4,5,4,2,3,4,5,6,6,0,4,5,6,6,6,7,7,8,8
|
||||
After 14 days: 3,4,3,1,2,3,4,5,5,6,3,4,5,5,5,6,6,7,7,8
|
||||
After 15 days: 2,3,2,0,1,2,3,4,4,5,2,3,4,4,4,5,5,6,6,7
|
||||
After 16 days: 1,2,1,6,0,1,2,3,3,4,1,2,3,3,3,4,4,5,5,6,8
|
||||
After 17 days: 0,1,0,5,6,0,1,2,2,3,0,1,2,2,2,3,3,4,4,5,7,8
|
||||
After 18 days: 6,0,6,4,5,6,0,1,1,2,6,0,1,1,1,2,2,3,3,4,6,7,8,8,8,8
|
||||
|
||||
|
||||
Each day, a `0` becomes a `6` and adds a new `8` to the end of the list, while each other number decreases by 1 if it was present at the start of the day.
|
||||
|
||||
In this example, after 18 days, there are a total of `26` fish. After 80 days, there would be a total of _`5934`_.
|
||||
|
||||
Find a way to simulate lanternfish. _How many lanternfish would there be after 80 days?_
|
||||
|
||||
### Part Two
|
||||
|
||||
Suppose the lanternfish live forever and have unlimited food and space. Would they take over the entire ocean?
|
||||
|
||||
After 256 days in the example above, there would be a total of _`26984457539`_ lanternfish!
|
||||
|
||||
_How many lanternfish would there be after 256 days?_
|
1
data/Y21/day7/data.txt
Normal file
1
data/Y21/day7/data.txt
Normal file
@ -0,0 +1 @@
|
||||
1101,1,29,67,1102,0,1,65,1008,65,35,66,1005,66,28,1,67,65,20,4,0,1001,65,1,65,1106,0,8,99,35,67,101,99,105,32,110,39,101,115,116,32,112,97,115,32,117,110,101,32,105,110,116,99,111,100,101,32,112,114,111,103,114,97,109,10,273,102,514,428,300,13,9,457,92,169,1654,471,479,178,158,124,354,83,705,30,80,199,632,31,840,580,1228,1597,151,1374,1665,469,43,1113,103,1,1456,132,2,618,423,824,789,145,485,585,543,694,1266,866,1276,726,680,1714,503,79,137,208,8,1447,455,33,1098,1346,1028,178,1095,21,19,52,668,29,382,1659,310,225,21,15,258,915,434,92,181,120,408,612,684,2,5,1507,127,746,203,66,4,82,440,1796,166,515,216,422,175,1643,240,100,178,375,487,134,599,581,38,101,19,882,1580,282,228,409,1124,409,255,1004,90,123,146,1130,461,84,9,1537,240,42,812,815,72,140,299,317,398,982,340,529,521,204,1137,895,912,313,27,540,638,403,188,163,133,34,1038,1597,440,200,275,2,1057,682,108,340,1096,361,2,242,464,392,432,334,955,145,275,605,858,173,375,435,3,3,784,396,324,1004,25,794,61,1358,752,31,563,23,407,886,870,501,1353,195,751,1407,10,874,31,33,589,124,403,205,225,40,1510,150,172,74,9,715,39,14,36,1775,29,1094,1007,199,4,26,301,878,751,538,33,102,109,297,236,119,195,431,34,179,827,6,204,91,594,65,255,1136,820,163,1508,388,680,968,1587,235,294,543,197,640,143,95,28,814,1053,827,167,54,606,0,823,3,340,619,195,31,216,330,287,382,676,392,5,1233,248,1000,323,872,234,316,4,112,663,113,1402,357,416,148,53,102,681,15,294,407,269,297,386,4,254,1666,454,139,1173,65,572,132,3,368,290,271,716,646,626,1727,411,196,181,1256,92,29,4,337,207,557,425,43,465,35,85,1218,241,936,247,94,1433,1002,400,624,88,1072,1048,370,101,264,78,379,27,65,672,1368,692,822,1020,317,472,1019,298,486,2,18,163,1304,994,952,455,454,661,1,473,561,313,92,425,218,29,49,618,790,615,347,462,169,275,247,1445,1880,225,1778,159,176,569,32,529,602,34,365,84,753,253,962,137,917,401,507,242,451,751,67,20,1208,411,226,829,317,283,219,154,683,30,1092,24,386,24,117,545,35,188,621,14,1453,24,892,330,337,754,407,481,906,643,552,864,808,360,704,118,368,297,1446,1348,104,1077,588,298,141,971,2,801,74,434,663,543,872,447,368,109,292,526,933,489,65,33,1061,1030,727,718,62,31,518,457,1569,815,422,187,211,1193,256,811,88,65,275,998,618,113,208,160,113,270,1085,295,20,161,117,134,1045,132,28,29,779,1108,24,801,240,184,414,79,335,98,486,195,100,302,574,561,353,8,260,1,540,584,410,1299,266,44,1120,877,252,377,849,83,547,637,827,298,1151,222,90,533,551,203,203,67,881,6,812,88,1314,178,169,576,885,767,278,1565,154,108,543,31,100,190,298,254,1478,594,644,957,177,20,1578,482,121,106,841,195,16,51,561,205,55,97,107,380,128,655,629,995,1424,1005,276,838,143,506,450,56,172,955,20,1045,253,436,1016,1106,68,540,807,265,405,301,539,1236,874,986,1092,274,1208,738,89,107,510,90,15,1402,313,712,35,222,494,125,113,290,259,274,214,70,1416,242,1312,1023,974,128,1787,91,13,992,84,673,185,375,385,0,285,135,116,105,26,103,929,733,567,294,174,82,1181,941,161,1242,387,20,882,1789,1164,1157,936,1110,1142,1308,657,931,29,603,1001,157,22,786,161,835,459,843,50,3,51,42,476,509,1214,733,1102,1011,0,832,1186,246,284,503,455,146,398,13,1109,106,90,511,1232,1837,580,285,86,1388,1199,195,225,742,194,1448,1732,309,1074,1380,251,1010,137,382,1367,490,1828,47,11,888,251,16,37,393,1407,233,5,814,780,850,22,1196,957,492,4,254,745,580,651,225,1072,872,323,618,24,303,79,7,75,11,15,65,449,205,103,836,150,111,424,786,194,1752,55,674,1469,1050,891,50,792,0,381,31,152,141,91,1521,420,18,779,450,68,929,122,106,7,142,185,355,768,581,1024,140,438,350,1838,815,977,23,663,324,30,7,408,461,40,108,203,459,530,69,120,177,962,162,1566,253,2,308,232,42,1564,1161,48,270,253,83,652,247,539,166,159,856,331,1701,970,1085,442,21,868,960,298,534,378,75,226,586,21,57,636,279,1112,63,1519,555,191,773,168,120,603,716,544,1546,378,418,149,138,1212,575,29,284,577,223,145,387,639,1204,154,613,48,116,307,341,716,3,831,987,629,1338,852,189,340,1213
|
1
data/Y21/day7/example.txt
Normal file
1
data/Y21/day7/example.txt
Normal file
@ -0,0 +1 @@
|
||||
16,1,2,0,4,2,7,1,2,14
|
63
data/Y21/day7/puzzle.md
Normal file
63
data/Y21/day7/puzzle.md
Normal file
@ -0,0 +1,63 @@
|
||||
# Day 7: The Treachery of Whales
|
||||
|
||||
[https://adventofcode.com/2021/day/7](https://adventofcode.com/2021/day/7)
|
||||
|
||||
## Description
|
||||
|
||||
### Part One
|
||||
|
||||
A giant [whale](https://en.wikipedia.org/wiki/Sperm_whale) has decided your submarine is its next meal, and it's much faster than you are. There's nowhere to run!
|
||||
|
||||
Suddenly, a swarm of crabs (each in its own tiny submarine - it's too deep for them otherwise) zooms in to rescue you! They seem to be preparing to blast a hole in the ocean floor; sensors indicate a _massive underground cave system_ just beyond where they're aiming!
|
||||
|
||||
The crab submarines all need to be aligned before they'll have enough power to blast a large enough hole for your submarine to get through. However, it doesn't look like they'll be aligned before the whale catches you! Maybe you can help?
|
||||
|
||||
There's one major catch - crab submarines can only move horizontally.
|
||||
|
||||
You quickly make a list of _the horizontal position of each crab_ (your puzzle input). Crab submarines have limited fuel, so you need to find a way to make all of their horizontal positions match while requiring them to spend as little fuel as possible.
|
||||
|
||||
For example, consider the following horizontal positions:
|
||||
|
||||
16,1,2,0,4,2,7,1,2,14
|
||||
|
||||
This means there's a crab with horizontal position `16`, a crab with horizontal position `1`, and so on.
|
||||
|
||||
Each change of 1 step in horizontal position of a single crab costs 1 fuel. You could choose any horizontal position to align them all on, but the one that costs the least fuel is horizontal position `2`:
|
||||
|
||||
* Move from `16` to `2`: `14` fuel
|
||||
* Move from `1` to `2`: `1` fuel
|
||||
* Move from `2` to `2`: `0` fuel
|
||||
* Move from `0` to `2`: `2` fuel
|
||||
* Move from `4` to `2`: `2` fuel
|
||||
* Move from `2` to `2`: `0` fuel
|
||||
* Move from `7` to `2`: `5` fuel
|
||||
* Move from `1` to `2`: `1` fuel
|
||||
* Move from `2` to `2`: `0` fuel
|
||||
* Move from `14` to `2`: `12` fuel
|
||||
|
||||
This costs a total of _`37`_ fuel. This is the cheapest possible outcome; more expensive outcomes include aligning at position `1` (`41` fuel), position `3` (`39` fuel), or position `10` (`71` fuel).
|
||||
|
||||
Determine the horizontal position that the crabs can align to using the least fuel possible. _How much fuel must they spend to align to that position?_
|
||||
|
||||
### Part Two
|
||||
|
||||
The crabs don't seem interested in your proposed solution. Perhaps you misunderstand crab engineering?
|
||||
|
||||
As it turns out, crab submarine engines <span title="This appears to be due to the modial interaction of magneto-reluctance and capacitive duractance.">don't burn fuel at a constant rate</span>. Instead, each change of 1 step in horizontal position costs 1 more unit of fuel than the last: the first step costs `1`, the second step costs `2`, the third step costs `3`, and so on.
|
||||
|
||||
As each crab moves, moving further becomes more expensive. This changes the best horizontal position to align them all on; in the example above, this becomes `5`:
|
||||
|
||||
* Move from `16` to `5`: `66` fuel
|
||||
* Move from `1` to `5`: `10` fuel
|
||||
* Move from `2` to `5`: `6` fuel
|
||||
* Move from `0` to `5`: `15` fuel
|
||||
* Move from `4` to `5`: `1` fuel
|
||||
* Move from `2` to `5`: `6` fuel
|
||||
* Move from `7` to `5`: `3` fuel
|
||||
* Move from `1` to `5`: `10` fuel
|
||||
* Move from `2` to `5`: `6` fuel
|
||||
* Move from `14` to `5`: `45` fuel
|
||||
|
||||
This costs a total of _`168`_ fuel. This is the new cheapest possible outcome; the old alignment position (`2`) now costs `206` fuel instead.
|
||||
|
||||
Determine the horizontal position that the crabs can align to using the least fuel possible so they can make you an escape route! _How much fuel must they spend to align to that position?_
|
200
data/Y21/day8/data.txt
Normal file
200
data/Y21/day8/data.txt
Normal file
@ -0,0 +1,200 @@
|
||||
dacefg fegab de dceb bedag dae bcgaefd bdacg fbgcad bgedca | acfebgd de dbagc deagcb
|
||||
cfgda fdebgc bfcdeag dbg afgedb efbad bg cdfeab gabdf abeg | dbg fbedgca gbea gbae
|
||||
dgcbe egdafcb bgcfe dgbf cgbafe db ecbfad deb agcde gdbfec | edb bcefgd gdfb edb
|
||||
fbgad bgedafc dcageb gcfbed bgdfca ebfag df fdg fcad bcagd | gdecfb dbfgac cgabd fd
|
||||
bacgd dbceg acedgf dgefb dcfbag cgbead edc ce abce bgecfad | abec gdcfea cbdga agbcde
|
||||
gcbfde gbdfeca ec afcbge egafb cdagb dbegfa ecaf bcaeg egc | egfcdb cgbdfe ebafgc cdfgeb
|
||||
fgcab efb afgbed deafbgc efgda dbgfce gbaef be fecdga deab | gfbdec bef agdef dabegf
|
||||
bcaegfd cbgd gb gfb bgdacf egfbad afdcb baecdf cfagb cagfe | gdcb defacb bg baefdg
|
||||
fgaecb fbad fgdae bedgacf defgc fa fga adcbeg gdeabf egdba | af agfdbce egcfd cgfed
|
||||
edfa dfbgac egabcf fbadce bcdaf cea gbfceda ae edacb bgced | ae eac dfae aefd
|
||||
decafb ae dbecg bdgae edfbgc bafgd egbcad fgcadeb cega eba | aedcbf ea eab gcae
|
||||
bfcge afdc bgaedc egdfc efcagbd fd dgfbae gfd dcgea defgac | ecdfabg efbgc edcfg gcfbe
|
||||
cgdfa cdaebg acedf egfc cae cfgdba ce bgfedac efbda dfcgea | afegdc fdeca debgac ace
|
||||
bcef abgec fabeg afbecg bfagd edbcgfa fe egadfc cagdeb efa | bgcdae gcdabe fgbae fe
|
||||
dgbaf faecbd cafebdg ade cdbfag ae abgdfe agdbe gecdb gfae | ae aed ebdcg dae
|
||||
bcgdfa bgaf bcf gabcd cfegadb cdfeg degbca bfcead dcbfg bf | acgbdf gabf bcf fcb
|
||||
cgdfae gfaebd dgfbca cdg dbgca cg cabde fdbga fcbg cdbfega | eagdfc gc egdcfa cbadfeg
|
||||
gdea acedfgb de deafc fbdca dfe ecdbgf cfage fceagb daegcf | dfeca edf fde gabfce
|
||||
abecg efc dgbace edcgabf bafec begf edgfac fe cfdab fcbage | defagc dbcaf begf fe
|
||||
gdecfa ebafc egbfacd fec fdeb geacb ef cabdgf fbdeac cbdfa | cdafb fegcda fagcbde caefb
|
||||
efgcd abfgedc cgeb eacdfb cdegbf cgf egadf dbgacf dcbfe cg | gcf fgc bcdefg cbaegdf
|
||||
baefdg egdfc gebcda dae aegcbfd gbadc dgafbc cabe ae geacd | eadgc ea cdgba ae
|
||||
ba feadcb bedcfga gacef bac egadcf ebgacf cbfgd ebga afbgc | acbegf gcaebfd cagfb fbgac
|
||||
afdeg fb defb geabc gacbdf ebgadf bfa dacgfeb bfgea fadecg | gbcae fb faecbgd fgdcae
|
||||
bgedfca agfcbd cbfeg afde dfbage gacebd aedbg debgf dfb fd | cbgdae efbgd gaefbdc cegbdaf
|
||||
cbeda fgcead dfe ef ecfg cedaf bfdegac fabgde cagdf fdgcba | fecda dgebfac def gfadbe
|
||||
fde dgecf begcd gfcbae geacf fd efgbcad cadefg cdfa fdegab | df def dcfaeg gfaebd
|
||||
agecbd fbdag caebdf gefdabc fagbc cbfea fceg agfbce cg gbc | eagfbc dcaebg cbdeaf gc
|
||||
dbega gbefa aedcgb cebdg dcea ad gda cebdfga gfbced bcafgd | gad cdeabg gda aedc
|
||||
ebfgac cdbegaf facged dge caegbd gbeda agcbe de dbfga ecbd | dbce dge dcefag defbgac
|
||||
dfabce dacbeg gfbed bcgeaf afebd fdac debca egdabcf fa afb | abcde cbdaef gabecd dfgbe
|
||||
cgb fcdab fgeabc bedcgf dceg gcbfd cg defbg bfgdae gcfdeab | gced gdabcfe bdcgf bfagcde
|
||||
dgcb cdafb bgafd cgfdab adgcfbe cfdae agcfbe cb cab adebgf | dacef baedcgf cdefa cbdaf
|
||||
ebagcf bgaf gabec daefcgb gcefb fabdce begdca cfb fb defcg | edagbc bfgce bdeacf eabfdgc
|
||||
eadbcgf bcd befcd fcegd bd agcbfd cbefa fcbeda cafgbe ebda | bdacef efcabdg db dbae
|
||||
gdecf acfedb fgac degcb gfdea abdfeg fc cfdage fec bdafgce | gcfed fgca cf agfc
|
||||
bafecg gefac cegfb cea efba dcgbfe dbecga gadfc cbadefg ea | gfcae ea gefcbd afegc
|
||||
bafe ba dbcae fgcabde bda ebcfdg gcdae gabfdc bcfed fedacb | adegcbf abd eacfgdb cfadgb
|
||||
afcd geadb bcaedgf acfgb fgdabc cdbefg fbd gdfba fd egfcab | gdeba cdaf gcfba fcdgba
|
||||
edbgfac bceg fagedb ebfca eb cdeaf gdcfab gcbfea fcbga bea | bedcafg eb abe adecf
|
||||
cbdfge gabfce edabc bdfcag bcfdg gdef fce fe gbedacf bedcf | ef defg ecf cdbgaf
|
||||
bafge de ebcdgf dbega bde cadebfg cagfbe acdgb efad gdfabe | decbgfa bfgae gdeacbf ceafgb
|
||||
cgfdeb adfegc dce ce fgcdb cgdafb cdefgba cdebf gbec dafbe | ce egdfca ec fabde
|
||||
eabcgf fcgbed bfaedc cabfedg fd gcdfe cdeag fcgbe gdfb def | fde df gfbd efd
|
||||
aed ebfa gdefab bgfda dacgfb cdgfae ea bgaed debcg gefadbc | bdgfcae dfbga gdebc bfedag
|
||||
eafdb ceadf fac ebacfg ecdabf fdcabge badc egfadb ca ecgfd | eacdf gfdce bcda cfa
|
||||
adgecb cf cagf cfdgab abfdc cbf dfagbec cadgb fcgdbe adefb | dbcfa fabdc cfga bcdaeg
|
||||
bgdcfa fdc bfcaeg gfdea dc gacdfbe fadgc fgbca fbceda bgdc | cd cabgf bcagfd acgfd
|
||||
defbc gcfbae efg aedg eg cgfbdae cgefd daefgc bafdcg fadgc | gfe gcdfa gfdcba befcgad
|
||||
bfgeca gcade bec begac afcgbd beaf cgabf be fecdbg deabgfc | eb cbe efgbcd afbe
|
||||
ebfcd dce fadceb cd gdbafe fedab aedgfc dfbgcae acbd efbcg | edcfb bdaefgc cbegf cefbd
|
||||
fgbc egcfda bga abcedg cabfgd dbefa abgfd bg dacfg cfdgeba | fcgb aefdb eafcgd agdecbf
|
||||
dcega dacgbef gbadc dcafeg gdebaf ead ae gbfced faec efdgc | cegfadb acdeg ae dgecf
|
||||
afgcb adebcg bgdec bcgea dacbefg aeb febcgd egda ae defcba | edcafb gfdceab ea gabfedc
|
||||
adcge bge agbfcde eafdcb facgeb aecgb gabf fdcegb acebf bg | dcbefg gabcef cbfdge gfcbed
|
||||
cebdag ace gfdbec gcebd agcde gfacd ae aebg defcab gbdafec | ea fbedcg dbgce eadgfcb
|
||||
bdaegc eabgcf bgfae bfcag edcbgfa ebg eb geafd gcabfd cbfe | aefgb bge be ebafgdc
|
||||
cbedgf eabfc gacf gfe bedag gefbcda cedbfa fcbeag fegab fg | fabeg bcefgd fg egfabdc
|
||||
bdce dfcebg cbf fbgcea bc edcafg dcegf bfgeacd cdbfg adgfb | bfc acbgfe edgfc gfcbd
|
||||
cedafg ae gfbed eaf dace gdfac dgcbaf caebfgd faegd eabcfg | aedfcg dfgbe ae edbgf
|
||||
fgcde cdebg cfage dbcf gafdeb baegdc df gcbdfe fed dacgbfe | fd dfe debgc geacf
|
||||
ed deb dabgf gade aegdfcb cefba abefd dfcgeb bfdagc afdegb | dbe gbadfe gdea de
|
||||
gbadc gde agced ecagdb ge ecgbdaf cebdgf aebg fadec bacgdf | gde adbgcf aefcbdg cbagd
|
||||
eadgc gae geadfc cafe ae gdcfa cgebd bcfadg bcdegaf befgda | ecadfg fadgc gedbc gaecfdb
|
||||
geca ac abgfedc edfcg fdgbce eadcf fagbdc feadb fdeagc afc | dbfea efacd egca cgbadf
|
||||
fbdca ebcdaf feca fcgbde fba dfeabg gcdab fcebd gefadbc af | dbacf dfecb af bcdag
|
||||
bfdegc afdgec defgab fcade fdc ebcad cf fbgecad gadef acfg | dcf gfac fcd cgaf
|
||||
dgfbc badefc cbe aebf dgeabc eb cadef fabedcg ebdfc gdecfa | be dcfbg afced ebgfadc
|
||||
dfcg degfab dg gcdea cgbefda deacf bceag afdcbe agd edacfg | faedbg gebafd afecd dcaef
|
||||
fdbe cfeabdg acfbde df dagecf dfabc cagbd fad egfcab efcba | cbfda efbdac bfdca fd
|
||||
aefdcg bgcda cgedbf eb gdcbaef bdeag geabfd aedfg bge fabe | fgcebd geb ebfa fadegb
|
||||
aedb dbfca caebf adf ad gbcafed bcdeaf ebcgfa acgedf cfdgb | acefb daf aedb fbcad
|
||||
ecgdabf fdcge begfca bg dabfec bgfdca abgd bcfda cdfbg cbg | agdb cagefbd cfgdb afdebc
|
||||
cga ecadfgb gfcd gc fagcbe aedgcf dgfabe bedac fadeg cadeg | gdfc cdgf gcbfae fdgc
|
||||
ga acdg egfbcd fegcad aeg dbafe fdage eabfcg degfc dafbegc | cdgfbe fegda fbade fcbdage
|
||||
agdfe dgcaef eb fcdbgae gcdbf deafgb bgfeca bfe egdbf bdea | ebf ebf abde bdgfe
|
||||
agbef egdf baegdf cdfbag df ebcad bafecgd fedab afd acfbeg | fd decab bedfa feabd
|
||||
dabcfge ab abge acfeb fdecb bac aebfgc cgdbaf aefgc cadgef | bca fbecga ebcfd ba
|
||||
feagcb cgdbfe cefdbag dg gdabec dcg ecbga ecdga dgab ecfda | dgc cabegd bdga gebcad
|
||||
dbfaec gac cgdeab efgcd dfagbce cfabe ag acbgef afegc afbg | ga acebdg bcdefa ag
|
||||
aegcbd cgfba gbdafce agcdb bfg afgbdc fg fgabed bcefa cdfg | bfg bafgdc dgcf bgf
|
||||
edcbf gceafd dfbaeg cgefba dafeg daecf aec agdc bfadcge ac | cfbedag eac febdc dagbef
|
||||
fgadcbe daecg abfd af afg bgfcae fabged gedfa dbefg bgedfc | afg gaf dgfbe gacebf
|
||||
fgbca cdbfa fgedac cfegb ag agbfdc bgfaedc gac acebfd gabd | dfeacb acg cfdagb eadcbf
|
||||
fcgeabd beac cfgdba cgfeda bfcdea bfa gefbd ab bfdae dceaf | ab bfdge fdecag dcefab
|
||||
dafeg bdefac gcebaf gcfbed fdcea cd aecfb dcf ecgbadf acdb | eafgd dfeca acbd egbfdc
|
||||
cdgfe egc abdefg agfc adecbgf aefdg gc gecdab ebfcd efcdag | gdecf cbefd gecfd gbdafe
|
||||
edbf fdgbac bcd ecbda bfcead dafcbeg cfeba egbcfa db eagdc | ecdfabg faecb bcdea abfcde
|
||||
ecfag fcdba cbg adegcf bgef badcge ecafbdg gb fgacb cfbeag | cbg bacfd gacefb cfbga
|
||||
gafed gbefca bfe badcfge fb dcebga abegc gfabe abcf edbcfg | afbc feb cebga afbc
|
||||
fedga ecbdgf acef degba dfabgce cdfaeg cgdfe acbfdg af daf | fda gdefac eadfgbc bfeacgd
|
||||
cd cfd afcged eacfg dfegb cfdeba dagc ecgbaf efdgc cegfadb | cgda fgdbe dcf cfaeg
|
||||
bdfceg aefgcd bgade gbf acfb bgcadf gfacd bf fdgbace gfbad | bf efgcda ecgdfb dfgace
|
||||
abecg fdaegcb acdgb cbde edacgf gbdace ec aec cgfdab fbgae | gacedfb eagdfc gaedfc bdcgea
|
||||
gf cbfeag ebcag bdacge cafed ebgafdc gcabfd begf afg gfcae | fbeg facbdg bgecdaf dcgefba
|
||||
gfcda gcaefb ad cfedga adc daeg fecbagd dabefc cfbdg gfeac | ad ecafg cdfeag cdbfg
|
||||
cdbfg deb ebgfd bgfdce cfbgda dcef egfab edbcga gacfbed ed | efdgb fgbcd gcadfeb fdce
|
||||
fbcaed bgcf fbgdcea gbaec fdebga geb gb caegd cbafe gaebfc | cfgb egb gb dcbfaeg
|
||||
bged fgdbc ebfcad efacg fed dcgafb dbgcef cgdef cebadgf de | fcdeg gdeb ecfgd gcbedf
|
||||
adebgf agefd abdgcf dg acfde gaecfbd egbd agd efgab cfebag | fcebagd dagbcf gefda adg
|
||||
ae fbdea defgb bfecgd bgedcfa eadgfb ebdacg fadbc eab egaf | gfedbc acebgdf bcgade bdgfec
|
||||
adbfc eacbf abgcef dgfcea eaf faecgbd efgbc dfecgb ae gbae | gafdce gbea ea cdbgfe
|
||||
cdefg ecbafg fgda cfgea cafbegd acdebg dfceag gd ecdbf cgd | efdcg agfd ecfdg dg
|
||||
cbdeafg ed bafgde efcd dabfc dfcabe ecdba ead cbeag bagcfd | de cabfed ade eda
|
||||
dbefagc dfgacb cfegbd fbgdc gbe edbc degfa efbacg eb gebdf | fagbcd bcfdg gbfcad dbce
|
||||
bfdce de dgaebcf begcf acfdb ecgbfa cedg fbedcg afedgb bed | cbefd fdgbae de bde
|
||||
ca ace cbdega ecgfd eagbfd acbg bcafde dcgfbea aedgb agecd | ca eca acgb adgce
|
||||
bc cgb acfb dbcgfea bdecgf gfadbe abgfd eacdg fbcdag bdgac | fcegbd bcg cbedfg badgcfe
|
||||
ag gbefac cdebg bdceaf cdbfaeg gcadfb gaceb gab agef cabfe | fcgadbe cagfedb ebfacd ga
|
||||
fg gaced gdcafb egacf cbafge fgdabce fbge bfaced cabfe gcf | beafcd eafgc bfcea bgcedaf
|
||||
eafdc cedbfa dcaegf fcg fcbega ecfgd bgcdfea afgd fg ecdbg | facged fg ecfda dgfa
|
||||
fb badcg eadgfb bdgeac fdbcg bfg fcdagb bgcdefa efgdc abcf | bgf bf gaedfb bcaf
|
||||
dbcag da bgdce afcd gacdbfe cagfb gabcfe adg cbdagf begdaf | da cgdba bagfec da
|
||||
dgcbf cfbe egf ecdgfa bcedgf adbcfge degab fe bedgf cfdbga | fcdgbe agdcfb fe fe
|
||||
dacegbf afgec fgbdec degfa eacfgd gdbfae gec gc efcba gcda | dbagef cdbgef dfaceg degcfba
|
||||
ecbdf gfced bcaf fabgecd egbcda gfbade bc bce cbeadf debaf | bdface afdgbec cb aefgbd
|
||||
gefab cafdge db edfgc bcgd fegbd cabedf cabefgd cbedfg bed | bgcd fcdeg gafbedc fcbgeda
|
||||
cdbgfe gadcb afbdeg gfdbc gedfb dcfgea fbagdec befc cf dfc | bfdge acgebdf cdf decbfg
|
||||
egdc fgcbae cbg adbgc gbcdeaf cg aedfgb bdafc ebdag abecdg | daebgc gbdeca gc gdabce
|
||||
fdb fbacgde befda fb bfec cdgaeb aedcb afbcde agcdbf fegda | bfd fdb bcfaed eafgd
|
||||
eagfc dgba faged gdf gadfcbe dg dafeb cedfgb ebadgf edabcf | egadfb agbd bagd badgfe
|
||||
cgdbfe cfdabeg fcdbga edabg af bdecaf aecf daf fdbea cebfd | af af af ecaf
|
||||
cdgabe dafegbc gbedc cbaed gbe ecdfg bg gdab baegcf deafbc | bg bge cebgafd dabg
|
||||
ef afe facbged adcfg cfebad dgef gfcdba acdgef fgeac aebgc | badecf dfge gdacf gedf
|
||||
fedcbg gcdb gbecf dbagef fdb cabgedf aecgfb dfceb adecf bd | cgeabf egfcb db fbecga
|
||||
ceadgb fadbe fdbgea ac cdfa afdegcb abcef ecfbad eac cbefg | fabde ac bafcde abdfe
|
||||
dcg dgfab beadc fgac dcgefb dafbgec agdcb cg facdbg afgbde | gdc cfga dgfebac adebc
|
||||
ecgab eacbf acf dafbe edbgca gedfcba caefbg cf fcgb fcdgea | fbdaecg gdeabc cfa gbfc
|
||||
acgbf cedbg cfebg fecagb fcgeda ef gfe befa fagecdb gfcadb | egbfc gedcfa egdcb egcbd
|
||||
abecd bf acfegd dafcb cfb gcafdb fbgd cgfad befcdag fgeabc | bfc dfagce cfdba acebfdg
|
||||
gdf egabfc ebgfa gaedfb acbfd agde fbeadgc gbdcfe gabdf gd | agbcef fbgdace gfd gd
|
||||
bdge ge fcdgeba gaceb cdabef bcfga aegfcd egc bdcage adecb | eg dbfgcea ge ceg
|
||||
gefbd gce cedf becgfa acbdg bgcfde bcedg egbadf ce gacbefd | gbfde ecagbfd cge cdef
|
||||
fed dfbegca gdaec abdgce fgedac ef afcdb faeg ecbgfd dface | dfagec gefa cebagd faeg
|
||||
acbfd facbdg badgcef ecb fdegb cdea bdfce cbfade ec afbgce | bagecf ebc dcbfe efcabdg
|
||||
be cdgeaf bfcgd gcfabed gcabed abgedf bdgce aecgd caeb edb | gdfcb eadcg gabdce ebd
|
||||
bfegcad abdgc cebdag cg caeg cfdebg gcb degbaf adegb dcafb | bgc aceg cabdge debfgac
|
||||
eg fcbae fgabe fgcade gbfad dgbe edacbgf fgdbac fge dfeagb | gadbf abdgf gadbef fabeg
|
||||
aegfcd eba fbacd be ecgb aegcd cdgeba aedcb agcebdf fgedab | ebgadc dfagbec cdgae bdfeagc
|
||||
fcdgeab aef bedfag fbadc gaebdc dgaecf feacd fe egcf dcgae | gaced fe ecdgab bfdca
|
||||
egdba baecfgd debcaf gb gcfbed gecda fdgbea bgaf bdfae egb | gfdeab gb gbe ecgda
|
||||
ecgab adbceg cegfbd ceg gacd ecgbdaf fgeba acbde cdfabe cg | dabecf cgbdea fdabecg bfaecgd
|
||||
fcbg egdaf dbecfa abgec feb begadc eagcfb gbefa cgfdeba fb | fedga dfbceag cegafb efb
|
||||
fe agdbcfe eafgdb fae dceabg eafgcb fcadb agedb dafeb fgde | fdeg adcgeb fe deabcgf
|
||||
ebfgd ad abdgf ebcgfa fdaebc dba cadegfb gcda bafdcg cabgf | gdfab cbdgaf abgfc fagdb
|
||||
eadgfc gdbfca fgcbaed bcdg cg cgf gdbfa egfbda fcabe cbfga | gc gabfd fcg afecb
|
||||
acbefgd fgcdab bcga fgdbc fdabe fdbceg acd fcbad eafdcg ac | ca aebcfgd cfbdg cbga
|
||||
beacfg ecafgd fdcbg fd gcbfe dcf efdb fcgdaeb adgcb ebdgcf | fecagbd dabcg fd fd
|
||||
ecfga fcdbae afgebc egdfa cae fcgedba bgac ca bfceg cdfbeg | agdfe gcebf afegc bacgfe
|
||||
cafebd gfebca dceaf eabfc efbagd faedgbc abdc adf ad fcgde | cbad badc gcefd cbegfa
|
||||
fgdbc beca adc cbgead bdgae cfagde dfgecab gcdab afbedg ca | agbefd ac dac abce
|
||||
ecbdaf geadbc cfdbe fcdgabe adfcg ge ceg gcdef fegb fbcegd | cfdabe gdfce ecbfd ge
|
||||
baegfd cadgb gdcfb agec dcgaefb bcagde edgab acb ac ebfdac | agdbef bdaecf ac egca
|
||||
dbaec eadcg ga gadceb gcedf cga ecbfagd acbdgf bgea eafbcd | daegc ag cga afcgbd
|
||||
daefbc bdeacg bacdg gdcfe egab becdg bce acdebfg fbadgc be | cagbed ebcadg aecbgd dbgafce
|
||||
bfedagc gbafcd fead eafgc ef cfadg edfcga fce dgcbfe caebg | ef fcadg ef edaf
|
||||
fadgce egc fegda dafgbe dcabg gceda ce gcfbdea agbfce defc | egacd gecadf febcgda abcgd
|
||||
egcdf cagedf bacef bdcgefa bd cbfdga ebdcf fbd bdefgc gdbe | becaf efbdagc cdaebgf cfbed
|
||||
faebd ebdfga fagced fe gbfad dcbfga eaf egfb cgedafb ebacd | eaf efgb baecd efa
|
||||
bdega edaf fabdge fe dfebg cgefab gfbdc dcabge gcedbfa fge | cegbda defa feg agbed
|
||||
gdecaf defbg acgdeb badc gcaed fbaceg afdebgc ebc cb gdbce | cb bdceag bc dcbge
|
||||
bgfc agdefc dgabcef fegca eadcb bg gbfdae gbe cagbe cefagb | gb ceafg bcega gb
|
||||
cgb cg efabc dbaecfg cbedfg bcefg ebagdf gfdc debgf deabcg | fgbed ebgcad fedgcab cgbfe
|
||||
fecad egdfbc gadcfe eagfc aebcg fdag feg fecdab aedbgfc gf | gfe dfag cgbdfe gfcdeb
|
||||
gadfce bcadegf fcged cafbg bd dcgbfe dgb dbec dgbfc beagdf | bgd cgfbde bcfga gfdbc
|
||||
gdecbf efg fbcgae cfeadbg geab cagef gadfc eg bafedc cafeb | egf fgaec becfa gcefa
|
||||
bcf eadcbf dcfeb cegbd bfea gdcafb efcad cadefg gfbeacd fb | fb cfgaed eabf afebcd
|
||||
ebcdag bgaefdc aegf eg fgebc dbecaf abcef beg cbafeg fbgcd | afecbg feag efag bdfcea
|
||||
cadfbe cgba cb cgadfe acgdf fbdcg bcf fcabegd fedbg gbafdc | eadgbfc faegcd bfc cabg
|
||||
bcgefd fcabg dafgcb cadfe fadcb dbf bd gcdebfa cfgabe dagb | cadfb eabcfg gbafce gcabdf
|
||||
dcegfb efadbc fceabgd dcab db beafc abefgc agdfe fbaed bdf | dcegafb dfb bfd fbd
|
||||
abe be faced fegb cabedg dfabe adfbge cfaebdg gbdaf fcgbda | eagdfcb egadfbc adfebg agfbd
|
||||
cgaefdb cedgfb dcfbe gef gabfde fbagc fgbec gcde ge bdafce | dafecb ge gfe efg
|
||||
edgaf defbagc edcbfa cd cbgd cegad cde afegbc gcebda abegc | badcfeg cde fadge fbdcae
|
||||
abgfec abfe acf ceagf baecdg dfecabg fa afgdbc agbec dfgec | acf fa af afceg
|
||||
ebgfda deafbc bcedg adcgbf fagdb afcg gdbfc fdc cf fdgaceb | feacdb fcag fcd dbefac
|
||||
gdfba de dbgefc ecdf dceagb dgefb cbgfe dbe gabfced ecgfba | efdgb feacgb egabfcd gfbde
|
||||
fgad gac bgcfae dgcfbae ga dfgcb begdcf abgcd cdeba bafgdc | agdf ag cdgfb ag
|
||||
efbcd efda fdbacg fe bdcaf feb gdcbe bgaecf dcfbgea fcbeda | fe ef becgd cebgd
|
||||
dgefbac de decb abfdg dacegf gde cbegf efbgd gfbdec cafebg | fecgab dbec de dafgb
|
||||
gec bdcfea gbdfe gc fdabgec bgedac adbec agbc ebgdc afgcde | cagb gecabd bfedac abcg
|
||||
cf cgdea cdgfe egdfb dcf dafcbg fbce eagfdb dcfegb bdcgeaf | fceb fdc fcbe efcb
|
||||
bcdga cgb bacf gcafdb cfgbade baegd bdcfeg cdafg gaecfd bc | dbgae gbcfda acgdb fbac
|
||||
fgcdae geacfb gd cdefb dbfgea bdga defgbac fgd febga gfbed | gfd ebcfag dfgbe dbag
|
||||
bdeag fedab cafgeb gb decbag gbe bgcd dcgea fgdcae ceagfbd | cfgebda ebg cfaegdb gdbc
|
||||
fdebac cb bface agbcfde befcgd ecb dacb efcad bagef caefgd | eadbgfc dbac ecb egfab
|
||||
bdcea cbgfead dfc ecfb efgdac fc bfdac edbcaf dfbag cgdaeb | fc edbgacf cf dagecf
|
||||
bdgfca abegfdc fdg abfceg dafbge gacde agcdf fdcb df bagcf | fbcga ecgabf bcfd df
|
||||
befcadg ce bdfgce cbed fce fecgb gefacd bafeg gfdcb gbafcd | ebdc bgfce gfedca ecbd
|
||||
fbgce abgefd ecdfga abfc efcgba bdecagf abfeg dbgce cf cfe | fec bgdaef bcfge ebdfcga
|
||||
cgfdba dbcegf gac fadeg ca fcab gdaceb dafgc bdgfeca gdbfc | adcfbge gdfca ecgabd ebadcg
|
||||
dcaebf gfdceab bd ecbgd egacb cedgf bed dfgb fgadce ecfgdb | bgdcfe cdebg gebdc dbe
|
||||
dcbae aecgbd daebcf cbefag adgc ag dabeg aedgbcf gea egbfd | badcefg gefdb dacbe dgac
|
||||
fgcdbae cagfd de eagcbf cbaedf gebd edf dgecf cgbdfe ecfbg | afcdeb fed dbeg efd
|
||||
adbec bdecfg adbcegf fd ebfcd gdbaef efd cbfgea cdgf cfbeg | befgc ebdfc gcbfe bgefc
|
||||
fadbg aebgfcd edgafc ebdfac dbe efcad be agcdbe fceb dfbae | agcdeb bfec fceb cbef
|
||||
fcged gfbdec adebf adc cage adbefcg caefd ac cbfagd efagcd | ecgafbd dac ca gfcbed
|
||||
gcdba fecgd gfdceb dgeabf af facgd feca aegfdc ecabfdg dfa | fcdga adbgef cadbfge daf
|
||||
afdec faebc bdea fgbcad efdgca ba egdbfac fcegb cba acfebd | cebfda bdae adeb abde
|
||||
defgca efgbadc ecgba gecbfd db dabegf aebdg gdfae deb adfb | dcgaef edb bed becgdfa
|
10
data/Y21/day8/example.txt
Normal file
10
data/Y21/day8/example.txt
Normal file
@ -0,0 +1,10 @@
|
||||
be cfbegad cbdgef fgaecd cgeb fdcge agebfd fecdb fabcd edb | fdgacbe cefdb cefbgd gcbe
|
||||
edbfga begcd cbg gc gcadebf fbgde acbgfd abcde gfcbed gfec | fcgedb cgb dgebacf gc
|
||||
fgaebd cg bdaec gdafb agbcfd gdcbef bgcad gfac gcb cdgabef | cg cg fdcagb cbg
|
||||
fbegcd cbd adcefb dageb afcb bc aefdc ecdab fgdeca fcdbega | efabcd cedba gadfec cb
|
||||
aecbfdg fbg gf bafeg dbefa fcge gcbea fcaegb dgceab fcbdga | gecf egdcabf bgf bfgea
|
||||
fgeab ca afcebg bdacfeg cfaedg gcfdb baec bfadeg bafgc acf | gebdcfa ecba ca fadegcb
|
||||
dbcfg fgd bdegcaf fgec aegbdf ecdfab fbedc dacgb gdcebf gf | cefg dcbef fcge gbcadfe
|
||||
bdfegc cbegaf gecbf dfcage bdacg ed bedf ced adcbefg gebcd | ed bcgafe cdgba cbgef
|
||||
egadfb cdbfeg cegd fecab cgb gbdefca cg fgcdab egfdb bfceg | gbdfcae bgc cg cgb
|
||||
gcafb gcf dcaebfg ecagb gf abcdeg gaef cafbge fdbac fegbdc | fgae cfgab fg bagce
|
136
data/Y21/day8/puzzle.md
Normal file
136
data/Y21/day8/puzzle.md
Normal file
@ -0,0 +1,136 @@
|
||||
# Day 8: Seven Segment Search
|
||||
|
||||
[https://adventofcode.com/2021/day/8](https://adventofcode.com/2021/day/8)
|
||||
|
||||
## Description
|
||||
|
||||
### Part One
|
||||
|
||||
You barely reach the safety of the cave when the whale smashes into the cave mouth, collapsing it. Sensors indicate another exit to this cave at a much greater depth, so you have no choice but to press on.
|
||||
|
||||
As your submarine slowly makes its way through the cave system, you notice that the four-digit [seven-segment displays](https://en.wikipedia.org/wiki/Seven-segment_display) in your submarine are malfunctioning; <span title="Yes, just the four-digit seven-segment ones. Whole batch must have been faulty.">they must have been damaged</span> during the escape. You'll be in a lot of trouble without them, so you'd better figure out what's wrong.
|
||||
|
||||
Each digit of a seven-segment display is rendered by turning on or off any of seven segments named `a` through `g`:
|
||||
|
||||
0: 1: 2: 3: 4:
|
||||
aaaa .... aaaa aaaa ....
|
||||
b c . c . c . c b c
|
||||
b c . c . c . c b c
|
||||
.... .... dddd dddd dddd
|
||||
e f . f e . . f . f
|
||||
e f . f e . . f . f
|
||||
gggg .... gggg gggg ....
|
||||
|
||||
5: 6: 7: 8: 9:
|
||||
aaaa aaaa aaaa aaaa aaaa
|
||||
b . b . . c b c b c
|
||||
b . b . . c b c b c
|
||||
dddd dddd .... dddd dddd
|
||||
. f e f . f e f . f
|
||||
. f e f . f e f . f
|
||||
gggg gggg .... gggg gggg
|
||||
|
||||
|
||||
So, to render a `1`, only segments `c` and `f` would be turned on; the rest would be off. To render a `7`, only segments `a`, `c`, and `f` would be turned on.
|
||||
|
||||
The problem is that the signals which control the segments have been mixed up on each display. The submarine is still trying to display numbers by producing output on signal wires `a` through `g`, but those wires are connected to segments _randomly_. Worse, the wire/segment connections are mixed up separately for each four-digit display! (All of the digits _within_ a display use the same connections, though.)
|
||||
|
||||
So, you might know that only signal wires `b` and `g` are turned on, but that doesn't mean _segments_ `b` and `g` are turned on: the only digit that uses two segments is `1`, so it must mean segments `c` and `f` are meant to be on. With just that information, you still can't tell which wire (`b`/`g`) goes to which segment (`c`/`f`). For that, you'll need to collect more information.
|
||||
|
||||
For each display, you watch the changing signals for a while, make a note of _all ten unique signal patterns_ you see, and then write down a single _four digit output value_ (your puzzle input). Using the signal patterns, you should be able to work out which pattern corresponds to which digit.
|
||||
|
||||
For example, here is what you might see in a single entry in your notes:
|
||||
|
||||
acedgfb cdfbe gcdfa fbcad dab cefabd cdfgeb eafb cagedb ab |
|
||||
cdfeb fcadb cdfeb cdbaf
|
||||
|
||||
(The entry is wrapped here to two lines so it fits; in your notes, it will all be on a single line.)
|
||||
|
||||
Each entry consists of ten _unique signal patterns_, a `|` delimiter, and finally the _four digit output value_. Within an entry, the same wire/segment connections are used (but you don't know what the connections actually are). The unique signal patterns correspond to the ten different ways the submarine tries to render a digit using the current wire/segment connections. Because `7` is the only digit that uses three segments, `dab` in the above example means that to render a `7`, signal lines `d`, `a`, and `b` are on. Because `4` is the only digit that uses four segments, `eafb` means that to render a `4`, signal lines `e`, `a`, `f`, and `b` are on.
|
||||
|
||||
Using this information, you should be able to work out which combination of signal wires corresponds to each of the ten digits. Then, you can decode the four digit output value. Unfortunately, in the above example, all of the digits in the output value (`cdfeb fcadb cdfeb cdbaf`) use five segments and are more difficult to deduce.
|
||||
|
||||
For now, _focus on the easy digits_. Consider this larger example:
|
||||
|
||||
be cfbegad cbdgef fgaecd cgeb fdcge agebfd fecdb fabcd edb |
|
||||
fdgacbe cefdb cefbgd gcbe
|
||||
edbfga begcd cbg gc gcadebf fbgde acbgfd abcde gfcbed gfec |
|
||||
fcgedb cgb dgebacf gc
|
||||
fgaebd cg bdaec gdafb agbcfd gdcbef bgcad gfac gcb cdgabef |
|
||||
cg cg fdcagb cbg
|
||||
fbegcd cbd adcefb dageb afcb bc aefdc ecdab fgdeca fcdbega |
|
||||
efabcd cedba gadfec cb
|
||||
aecbfdg fbg gf bafeg dbefa fcge gcbea fcaegb dgceab fcbdga |
|
||||
gecf egdcabf bgf bfgea
|
||||
fgeab ca afcebg bdacfeg cfaedg gcfdb baec bfadeg bafgc acf |
|
||||
gebdcfa ecba ca fadegcb
|
||||
dbcfg fgd bdegcaf fgec aegbdf ecdfab fbedc dacgb gdcebf gf |
|
||||
cefg dcbef fcge gbcadfe
|
||||
bdfegc cbegaf gecbf dfcage bdacg ed bedf ced adcbefg gebcd |
|
||||
ed bcgafe cdgba cbgef
|
||||
egadfb cdbfeg cegd fecab cgb gbdefca cg fgcdab egfdb bfceg |
|
||||
gbdfcae bgc cg cgb
|
||||
gcafb gcf dcaebfg ecagb gf abcdeg gaef cafbge fdbac fegbdc |
|
||||
fgae cfgab fg bagce
|
||||
|
||||
|
||||
Because the digits `1`, `4`, `7`, and `8` each use a unique number of segments, you should be able to tell which combinations of signals correspond to those digits. Counting _only digits in the output values_ (the part after `|` on each line), in the above example, there are _`26`_ instances of digits that use a unique number of segments (highlighted above).
|
||||
|
||||
_In the output values, how many times do digits `1`, `4`, `7`, or `8` appear?_
|
||||
|
||||
### Part Two
|
||||
|
||||
Through a little deduction, you should now be able to determine the remaining digits. Consider again the first example above:
|
||||
|
||||
acedgfb cdfbe gcdfa fbcad dab cefabd cdfgeb eafb cagedb ab |
|
||||
cdfeb fcadb cdfeb cdbaf
|
||||
|
||||
After some careful analysis, the mapping between signal wires and segments only make sense in the following configuration:
|
||||
|
||||
dddd
|
||||
e a
|
||||
e a
|
||||
ffff
|
||||
g b
|
||||
g b
|
||||
cccc
|
||||
|
||||
|
||||
So, the unique signal patterns would correspond to the following digits:
|
||||
|
||||
* `acedgfb`: `8`
|
||||
* `cdfbe`: `5`
|
||||
* `gcdfa`: `2`
|
||||
* `fbcad`: `3`
|
||||
* `dab`: `7`
|
||||
* `cefabd`: `9`
|
||||
* `cdfgeb`: `6`
|
||||
* `eafb`: `4`
|
||||
* `cagedb`: `0`
|
||||
* `ab`: `1`
|
||||
|
||||
Then, the four digits of the output value can be decoded:
|
||||
|
||||
* `cdfeb`: _`5`_
|
||||
* `fcadb`: _`3`_
|
||||
* `cdfeb`: _`5`_
|
||||
* `cdbaf`: _`3`_
|
||||
|
||||
Therefore, the output value for this entry is _`5353`_.
|
||||
|
||||
Following this same process for each entry in the second, larger example above, the output value of each entry can be determined:
|
||||
|
||||
* `fdgacbe cefdb cefbgd gcbe`: `8394`
|
||||
* `fcgedb cgb dgebacf gc`: `9781`
|
||||
* `cg cg fdcagb cbg`: `1197`
|
||||
* `efabcd cedba gadfec cb`: `9361`
|
||||
* `gecf egdcabf bgf bfgea`: `4873`
|
||||
* `gebdcfa ecba ca fadegcb`: `8418`
|
||||
* `cefg dcbef fcge gbcadfe`: `4548`
|
||||
* `ed bcgafe cdgba cbgef`: `1625`
|
||||
* `gbdfcae bgc cg cgb`: `8717`
|
||||
* `fgae cfgab fg bagce`: `4315`
|
||||
|
||||
Adding all of the output values in this larger example produces _`61229`_.
|
||||
|
||||
For each entry, determine all of the wire/segment connections and decode the four-digit output values. _What do you get if you add up all of the output values?_
|
100
data/Y21/day9/data.txt
Normal file
100
data/Y21/day9/data.txt
Normal file
@ -0,0 +1,100 @@
|
||||
0198954334976942239109321545998999878998764656978999349899965478954987432389012356989932123998432123
|
||||
1997943129865890198998910239867899967999873249865988998799896567899876543478925689879899019896421012
|
||||
9886895997654789987987891998756898656987654598774877897545697878912988654567934598767688998789432123
|
||||
8765789869763567996545789876545999768998798797653656796536789989543499867688955697654567897678954235
|
||||
9876898753212456989434679987976789879239899898542348987421568997699989878999896898753656797569765376
|
||||
0987899854901345678923478998987999989998975959643459876542456789988978989998789999842349899678997487
|
||||
2398959769892957789012467899898999899897654345987678987543567999876767897987678898761018999789998598
|
||||
3599549898769898993123458987639998789789532123498989898654698999965459975698545789983567899899987679
|
||||
4989432999656799654364667996521989598678944234989796789765789798754368964679657899894589989999898791
|
||||
9879949897545678967975878989432978436567954349876535699977997679854234943569869998765999879989769890
|
||||
9867898765434589878989999578999767323457895456995323798989543569542123899699878909879876768678953989
|
||||
8757989987645678989092123489987656212345889679899213997999432198654235678989989212998875654569769979
|
||||
7645678998656789299297334569876543101345678998778939876898954569764345989678994323497964323468998767
|
||||
1534578999767899198986586679987764512387989876567898765457895678985469994569765434596543212356789156
|
||||
0123467899898978987897898899998975643478995965479986543234999789876598989678998645987632103568993245
|
||||
4235678979979569876789919968999997856569654987567895432155679896987897878989679876898545314789754766
|
||||
5546789765765459984568923459987898768679653498689976621019989954398986567893498989987695424898769889
|
||||
7856797654432397213467894698876569878789432398798986543198895432129875456912987698998986546789878996
|
||||
9768899843101976434688999987766456989998953789897897654987789843299764347799654567899797656789989645
|
||||
9878998754233987549789988996651238898767895678956798969976699754987643235678965678987659878999993234
|
||||
7999899965654797679895677965430356789456976799347679998764568967999654016889986789876542989569892129
|
||||
6986789876795698989923456894321246794239897893234578976543487898998765127999999899987821093459789098
|
||||
5435667987986999999874567896534356789949789921015679895322346789019976238989899999876542912998678997
|
||||
4323459899897898998965678997647467997898679933234599797401367898923987349976678989987669899876467896
|
||||
3212998789789987987989789398766567896976568899545988689212456897945698967895457978999798767987679965
|
||||
4309875646678996556899891249877899954320446798959876578999567976899789879964349865789899654598989334
|
||||
3219554234569219434989954398988921967431234567898765467678978965789893989998599974899999543499793212
|
||||
4997432123678998999879765987699999876546346788999985336589989994896902498987678989989998932987654329
|
||||
9876543245989987889968999876543989987687897899999896213467999876895213567898789299765987821298775678
|
||||
8987854556894345678956789998679876999798998999889798101578910987894394678939891019873496532999896799
|
||||
7698976677954234599745699998798884899899329998765689313489421598965989899423932198921987649899989890
|
||||
6549987988943123689656789899987653668993210987654569986578932349896978989214949997532398999768878921
|
||||
7756798999431012698769998789776542557989421297643467899789543456799869878929898889543459987653567992
|
||||
8987899998999243459898789698654421345678932398654578979899956789987659767898787678999767998542456789
|
||||
9898968997988954568965698598793210156899645469767699467989897899897745656989654589988978987631375699
|
||||
8769656986567897679654596439987921367998756899878789359878789998765432345679543598767899997410134789
|
||||
9954249987456898989768987521986434456789867987989992198767678999876521349889901987543339876321245679
|
||||
9865198765345689199979765430987545768999998946797893987654597898765435478999893976432129865434357889
|
||||
9991029984296891019999876542398969899998999235986789976543656799876556569998769896554239876545667998
|
||||
8789129876989932998945989653989898989987898949875696989652345789987987678987657789665445987676878957
|
||||
8688999999878949877896798799765787679896767898754245799921235689298998789876546678989589998989989545
|
||||
7567989987857899765679979987654567589765456789876126999832367893109459899997434568997678999898998734
|
||||
5499879765436987654569865598743423469876877896521099898753456954212345999998528678998789987787899949
|
||||
6987656976524599543678954329832102378989988965433987659864869896793469998999838989899899876576999898
|
||||
9998767897434598956789765497643236899993499977654976540975998789954598987898646898765998765445899656
|
||||
8999879976545987997899876987654345678901943988779765321986989697899987876789757999954239654325678945
|
||||
7786989997659576889978998998785459789219892399889898732399878545678976745699768998932199867214589656
|
||||
6565799989897465679567899999897878994329789902999987543498767435699765434567978987893987654323578997
|
||||
5444679878986323493456789988998999789998678893498998684569854324589854315779989876789998875634699398
|
||||
6323498759875437894667899976549446699876558789976439795698765416678952104567899865698999987849893249
|
||||
3212989643986556789988999895432234579987345679765429898789876527899543212388998764587992198967910123
|
||||
5459876532398767993299998794320123992392136789975212969899998678987656623499987653376789349978921235
|
||||
6597954321239878932134987689321399889989015699894353459999598789798787536567899762165567999989932446
|
||||
7986543210157989321029876578932988779678923456789877678998439896689876547679959854013456789299873457
|
||||
9797676521238996432134965489549976567567894578897998989987510975468989658789749862134567892198765678
|
||||
4598997432347896543549876379698765456456789679986549999899329876349898778895539879345679943999986899
|
||||
3569986543456789656867976568999866331345678989995434987679949983299769899984320987656997899892197975
|
||||
2345698754578999767979498689987653210234899998976219876569898654987653969865421498767896798789998944
|
||||
1236999885679789998989239795498769329946789877894398765498789769765432358977432389878975434569899432
|
||||
0349899976789678999894349892349898998897898966965987654397689879877841237898743467999664313467789901
|
||||
1239798999894589998765956901467997987789956645899899765298797989998930356789654569876543201234569892
|
||||
2998667899923458929879899892568985465678943234789678953129896595699321268898789678987654562365698789
|
||||
9876545798912347912998789789879875323489432123596567891012999434987532379999898799498765684578987678
|
||||
9988432977893456894989645678998763218796543034789437789234678929876543456789959989329876795789876567
|
||||
9895431866789579999876534569899953105689656546797645678945799101987854579899349878912989897899865456
|
||||
8765310145689998999998321345798767214578998687899856789996893212398965699998969769653499998912976367
|
||||
7654321234567896789874210127789874323789998788967967892987894323569879789987898758994689579201985458
|
||||
8765432365679944598765331235699985434899999899459878921998995437689989891976789347889793459399876769
|
||||
9878944456989533459876452346789996546789896912345989439899986568789299932987894236778965998988987878
|
||||
0999876567895421246986567487997897657899774101236799598788997679892109893498956124568999876267898989
|
||||
1989998698996730178987878998976798768987653212345678987697898793999298789569743013456789994348939996
|
||||
9878999789987541359998989659365679899987654323657799986576799892398997678998652124567893986789129895
|
||||
8767899893496432499899997643234899999998765434567899975425678901986554599998543236899964799891098796
|
||||
7654698921297543987789999832123789998799886865678949876534799999876423678987654545678975678942989689
|
||||
9543567890987665996578898753435678987689997976789421987646789987654213589998778659899986789659876548
|
||||
8912478999998789875466789766576789986579999987896610198757891098785344567999899789967997898998998957
|
||||
7894567898999896984345678987687898765459892199965423459868989129887895678999929892158998987897899868
|
||||
6789789987899934986456789298998949654328789013986594569879578934999976899889012999349989675876789979
|
||||
4899998756789915698567899129989939869212578923987989978989459899653987897678929998959876543365679989
|
||||
5999897647897896987678988999867899998923459994699677899392398798942398928568998997899985432124567890
|
||||
6898765530146789999789567989654678987995767989987566789210987687890999312456987976899899321013479931
|
||||
7919654321237898989892379878943569895789999878976455899391296566799889202369876345697778934154567899
|
||||
8929865445356987579954998769892398784679889767895324988989987434789768943459965237986567953245679978
|
||||
9934986656767893467899877555679989613498767856991015976568986523598546899698954356975468967456789767
|
||||
9899997768978922279923965434568976501987845345689129896459876434987656998987895479864357978697997656
|
||||
8767898989989210189109874323457898319876431234568999765345987845699767897796989599865267899789996545
|
||||
7656899591095332398998765446568987634986545489679988653236798956789878986675978987654356789899989326
|
||||
8767999432986745567899976757678976545697657567989876542124569979892989965434567898865468993999878939
|
||||
9898998993987857898967987878789989656789967979399986321013456989901399876512367899979878921298769998
|
||||
2999987789998969999458998989896799778999878989298765442134567895313567985403456897989989942987657897
|
||||
1298986678999878998569769997955459889901989892129876653485698989494579875314567896998796899996545956
|
||||
0987854567999999987678956976545368999892398763012989764578789876989989994323698965789545678989434345
|
||||
9876783456889323498789543989631259999789987653135699876689992345678999985554789654678924579879921267
|
||||
9965432345679212589896532398920345987678998774256789987799101256799339876765896532467896798768895348
|
||||
9876543456798954679987421987934599793589998765345678998898942349989212989876897651278999986545789458
|
||||
3998654567897799798899910986899987654678939978458799769987895498968999995989965432345698765435679567
|
||||
2198777679976687987678891965678999769899212989569897654216789987654678954399877643567899654323569678
|
||||
1019888789465456986546779878999239878989103498678998765345678999543789967894998654689998795434578989
|
||||
2123999994312349876534567989654347989378915679789329876557789987654567898923498765891019986795989295
|
||||
3235986543201456987677678999987656896567923899893212998768994399765678999434569978943523987886892123
|
5
data/Y21/day9/example.txt
Normal file
5
data/Y21/day9/example.txt
Normal file
@ -0,0 +1,5 @@
|
||||
2199943210
|
||||
3987894921
|
||||
9856789892
|
||||
8767896789
|
||||
9899965678
|
78
data/Y21/day9/puzzle.md
Normal file
78
data/Y21/day9/puzzle.md
Normal file
@ -0,0 +1,78 @@
|
||||
# Day 9: Smoke Basin
|
||||
|
||||
[https://adventofcode.com/2021/day/9](https://adventofcode.com/2021/day/9)
|
||||
|
||||
## Description
|
||||
|
||||
### Part One
|
||||
|
||||
These caves seem to be [lava tubes](https://en.wikipedia.org/wiki/Lava_tube). Parts are even still volcanically active; small hydrothermal vents release smoke into the caves that slowly <span title="This was originally going to be a puzzle about watersheds, but we're already under water.">settles like rain</span>.
|
||||
|
||||
If you can model how the smoke flows through the caves, you might be able to avoid it and be that much safer. The submarine generates a heightmap of the floor of the nearby caves for you (your puzzle input).
|
||||
|
||||
Smoke flows to the lowest point of the area it's in. For example, consider the following heightmap:
|
||||
|
||||
2199943210
|
||||
3987894921
|
||||
9856789892
|
||||
8767896789
|
||||
9899965678
|
||||
|
||||
|
||||
Each number corresponds to the height of a particular location, where `9` is the highest and `0` is the lowest a location can be.
|
||||
|
||||
Your first goal is to find the _low points_ - the locations that are lower than any of its adjacent locations. Most locations have four adjacent locations (up, down, left, and right); locations on the edge or corner of the map have three or two adjacent locations, respectively. (Diagonal locations do not count as adjacent.)
|
||||
|
||||
In the above example, there are _four_ low points, all highlighted: two are in the first row (a `1` and a `0`), one is in the third row (a `5`), and one is in the bottom row (also a `5`). All other locations on the heightmap have some lower adjacent location, and so are not low points.
|
||||
|
||||
The _risk level_ of a low point is _1 plus its height_. In the above example, the risk levels of the low points are `2`, `1`, `6`, and `6`. The sum of the risk levels of all low points in the heightmap is therefore _`15`_.
|
||||
|
||||
Find all of the low points on your heightmap. _What is the sum of the risk levels of all low points on your heightmap?_
|
||||
|
||||
### Part Two
|
||||
|
||||
Next, you need to find the largest basins so you know what areas are most important to avoid.
|
||||
|
||||
A _basin_ is all locations that eventually flow downward to a single low point. Therefore, every low point has a basin, although some basins are very small. Locations of height `9` do not count as being in any basin, and all other locations will always be part of exactly one basin.
|
||||
|
||||
The _size_ of a basin is the number of locations within the basin, including the low point. The example above has four basins.
|
||||
|
||||
The top-left basin, size `3`:
|
||||
|
||||
2199943210
|
||||
3987894921
|
||||
9856789892
|
||||
8767896789
|
||||
9899965678
|
||||
|
||||
|
||||
The top-right basin, size `9`:
|
||||
|
||||
2199943210
|
||||
3987894921
|
||||
9856789892
|
||||
8767896789
|
||||
9899965678
|
||||
|
||||
|
||||
The middle basin, size `14`:
|
||||
|
||||
2199943210
|
||||
3987894921
|
||||
9856789892
|
||||
8767896789
|
||||
9899965678
|
||||
|
||||
|
||||
The bottom-right basin, size `9`:
|
||||
|
||||
2199943210
|
||||
3987894921
|
||||
9856789892
|
||||
8767896789
|
||||
9899965678
|
||||
|
||||
|
||||
Find the three largest basins and multiply their sizes together. In the above example, this is `9 * 14 * 9 = 1134`.
|
||||
|
||||
_What do you get if you multiply together the sizes of the three largest basins?_
|
Reference in New Issue
Block a user