Add instructions and input files

This commit is contained in:
Blizzard Finnegan 2021-12-07 02:56:58 -05:00
parent d974ff5bad
commit 9aa58918ca
14 changed files with 1510 additions and 0 deletions

View file

@ -0,0 +1,46 @@
--- Day 1: Sonar Sweep ---
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 carried into deeper water 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?

View file

@ -0,0 +1,35 @@
rt 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?

View file

@ -0,0 +1,34 @@
y 2: Dive! ---
Now, you need to figure out how to pilot this thing.
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?

View file

@ -0,0 +1,27 @@
--- 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?

View file

@ -0,0 +1,35 @@
--- Day 3: Binary Diagnostic ---
The submarine has been making some odd creaking noises, 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.)

View file

@ -0,0 +1,35 @@
--- 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.)

602
day4/data/input.txt Normal file
View file

@ -0,0 +1,602 @@
68,30,65,69,5,78,41,73,55,0,76,98,79,42,37,21,9,34,56,33,64,54,24,43,15,58,61,38,12,20,4,26,87,95,94,89,83,74,97,77,67,40,63,88,19,31,81,80,60,14,18,47,93,57,17,90,84,85,48,6,91,7,86,13,51,53,8,16,23,66,36,39,32,82,72,11,52,28,62,70,59,50,1,46,96,71,35,10,25,22,27,99,29,45,44,3,75,92,49,2
68 16 83 90 69
14 89 72 33 6
63 21 43 64 76
79 65 87 98 85
41 24 32 53 93
15 94 72 30 6
14 80 66 4 78
44 81 68 67 96
65 21 64 97 35
84 90 28 60 2
97 39 61 15 94
75 14 66 98 31
58 80 9 64 56
19 42 16 85 37
25 22 38 65 82
86 31 71 11 56
99 12 17 10 46
5 33 85 61 2
30 1 28 88 66
15 38 21 54 64
38 52 84 75 91
77 5 49 71 31
45 1 60 0 10
68 29 98 36 34
61 90 93 14 12
91 66 28 41 78
89 16 10 77 39
84 57 44 32 47
60 62 26 21 50
75 61 24 54 93
2 69 99 8 20
14 35 61 85 73
39 94 37 63 12
57 23 30 50 17
34 70 19 28 77
50 82 41 59 52
43 76 85 63 48
56 67 60 33 45
42 9 91 23 16
96 6 34 30 44
0 41 24 42 83
17 1 34 29 71
46 67 86 64 21
95 36 6 38 62
93 8 30 77 44
6 94 11 14 83
65 85 97 37 55
56 19 91 69 1
26 59 13 96 68
4 28 7 45 53
96 78 2 32 65
3 63 74 17 4
76 11 91 48 70
71 55 69 13 49
88 30 23 59 10
28 4 34 64 47
99 86 44 59 43
50 91 35 92 51
32 21 19 74 33
10 29 66 52 94
0 27 12 23 71
54 59 32 47 45
22 85 94 34 31
29 68 44 61 62
96 46 52 33 69
37 79 34 17 56
26 62 3 77 80
88 35 71 87 36
89 60 86 19 48
82 97 95 85 0
62 49 48 98 10
89 37 50 64 17
80 5 26 42 51
58 74 6 20 14
72 2 9 40 69
71 37 47 21 39
36 29 26 82 53
10 17 96 15 43
8 92 19 6 32
77 89 38 54 13
16 58 67 23 98
43 42 26 46 13
32 22 27 20 21
37 33 55 86 1
99 40 17 44 94
81 59 53 27 36
11 88 92 57 44
2 26 93 94 77
76 47 82 19 75
99 34 98 37 32
28 13 57 99 7
42 93 10 76 43
1 52 3 20 53
82 81 51 2 92
94 35 49 37 0
5 30 61 77 44
82 67 98 1 90
18 62 27 24 15
16 20 71 69 19
85 96 25 7 55
39 51 4 32 30
64 22 29 48 60
78 31 44 59 92
65 10 68 84 16
40 70 35 26 56
54 83 12 79 66
21 49 70 2 24
20 51 71 99 50
82 36 57 96 22
78 52 67 33 72
3 62 5 14 63
54 75 28 22 51
1 55 86 30 70
9 6 92 83 85
71 78 96 47 17
71 59 38 27 2
90 6 97 75 84
29 69 45 11 65
46 31 79 4 8
51 76 74 87 19
83 67 10 39 57
7 63 12 59 2
54 99 95 88 40
38 71 84 61 56
81 90 36 58 19
4 47 21 28 46
22 40 94 83 86
82 17 43 0 45
55 36 68 35 84
52 24 6 80 2
29 16 75 26 87
6 82 67 36 24
13 95 35 43 40
80 68 0 79 71
34 44 21 30 85
91 25 24 15 23
93 14 50 75 74
88 30 64 52 8
1 7 0 4 80
96 82 98 81 67
52 21 71 78 4
45 73 27 30 56
7 93 67 6 1
54 20 57 69 2
94 36 89 46 68
86 95 15 7 18
8 87 29 11 74
71 72 43 76 40
6 60 44 19 99
97 85 5 39 77
49 14 5 48 33
95 21 30 1 47
87 84 85 10 24
32 86 99 31 23
69 2 43 37 60
57 48 99 49 73
31 92 76 60 96
47 28 15 70 26
68 19 56 67 95
12 23 45 88 6
77 49 23 42 62
47 7 80 43 4
59 72 87 14 84
66 81 96 97 78
61 91 8 17 48
21 25 1 82 20
78 31 15 30 73
46 11 13 35 79
60 22 97 32 4
23 88 63 17 75
6 3 41 5 44
91 21 32 49 81
29 85 47 20 14
99 31 43 22 69
90 4 45 8 16
12 15 96 3 21
38 71 16 39 24
77 82 57 55 92
27 17 19 73 31
74 48 34 72 14
80 16 10 79 55
93 60 4 0 29
7 97 3 9 86
43 67 78 64 35
44 83 40 33 12
36 88 22 21 70
30 60 13 6 41
71 89 86 17 39
73 0 75 32 9
5 10 83 85 99
40 41 76 38 25
21 49 79 47 39
27 88 34 81 24
69 64 36 32 4
57 5 58 67 56
25 95 41 27 19
93 0 29 56 8
2 17 66 11 82
96 55 44 39 5
67 4 33 62 40
85 12 46 59 36
91 29 19 63 0
72 49 14 6 95
18 50 60 67 80
10 62 39 82 58
11 87 4 76 75
64 47 26 74 98
89 30 68 21 88
45 41 77 67 53
96 92 44 1 18
33 26 21 8 76
15 27 41 43 52
64 85 56 57 66
11 73 62 69 4
36 13 94 86 55
93 80 67 23 6
57 20 29 69 1
76 96 72 95 33
32 91 52 16 83
26 54 13 94 47
56 0 58 15 45
91 40 86 61 60
14 47 30 5 24
21 12 33 69 41
78 98 9 99 46
59 1 63 96 14
15 56 23 85 84
29 98 44 87 46
75 8 21 54 65
80 30 40 45 6
99 40 87 4 63
64 78 50 74 58
37 47 61 48 59
65 56 45 89 67
18 70 71 90 32
42 35 1 9 90
89 13 0 88 17
67 82 31 77 91
60 29 68 10 64
20 92 46 71 95
0 32 81 13 63
87 17 2 56 69
23 33 29 67 24
98 95 86 36 31
99 42 35 93 1
71 79 38 84 29
26 31 73 1 48
94 85 3 82 89
19 17 98 92 47
96 45 11 70 51
14 69 61 56 33
98 88 82 76 66
87 92 42 99 35
0 68 6 44 47
4 91 54 62 23
10 23 20 40 96
33 0 21 94 25
4 67 30 88 54
43 41 60 1 82
18 78 74 98 91
60 95 53 7 11
67 54 44 18 0
89 98 24 55 37
39 5 27 62 21
75 25 43 47 71
5 95 60 19 3
13 15 42 97 67
61 79 7 12 39
53 58 89 25 34
9 11 96 21 66
89 97 45 84 67
37 22 64 39 95
68 63 6 90 80
92 26 33 35 19
29 70 5 72 31
52 46 53 6 31
77 8 59 99 49
11 48 4 90 91
41 70 58 16 44
7 61 9 80 50
75 0 38 37 33
99 66 98 14 62
46 51 43 34 24
71 92 80 32 22
60 39 17 52 45
92 49 80 99 16
6 77 65 9 4
34 91 86 43 21
0 3 27 84 81
28 5 19 95 76
5 40 26 89 1
51 30 75 46 31
35 58 86 80 0
98 38 27 81 93
63 60 39 65 87
27 56 90 44 60
48 68 47 96 73
75 13 80 12 38
81 21 20 46 97
67 6 72 76 2
33 96 4 55 49
74 43 54 6 51
30 0 75 28 62
90 81 2 83 68
39 95 70 84 42
97 22 15 30 45
92 96 50 16 42
39 23 89 21 2
72 98 58 48 82
94 11 1 86 84
41 13 84 51 76
33 63 0 62 18
81 32 57 68 21
20 64 47 24 93
7 56 27 66 30
52 81 85 92 3
15 91 19 13 93
36 77 74 37 26
67 16 73 89 33
43 90 38 31 29
1 52 96 66 86
30 15 26 82 42
8 94 41 54 5
84 23 72 77 7
34 53 18 69 90
7 67 35 2 36
91 51 56 85 32
98 22 76 97 71
70 29 68 44 1
8 80 42 46 93
4 13 90 64 97
44 28 17 42 18
72 77 11 35 22
25 73 41 1 26
51 8 92 43 2
6 68 51 73 39
32 60 34 74 18
5 95 11 8 62
23 3 70 94 54
36 20 29 10 26
66 80 77 82 62
95 25 33 50 14
94 0 91 46 23
59 47 96 26 15
69 6 2 34 75
72 66 35 81 69
48 44 11 16 40
94 5 3 51 54
89 6 78 37 59
76 45 8 18 10
30 46 96 56 69
66 29 32 74 4
85 84 99 87 92
22 50 64 15 57
78 47 1 48 10
66 48 90 67 23
3 21 73 71 18
97 52 64 80 94
49 42 75 47 38
4 28 19 68 57
53 46 56 84 57
55 45 85 89 76
80 26 2 36 23
92 10 30 18 69
67 49 21 8 44
51 47 85 41 8
70 34 98 30 16
82 22 18 95 73
65 21 49 5 15
56 19 17 23 46
25 28 47 84 8
35 90 13 39 15
50 86 41 33 51
57 73 87 45 5
31 22 48 7 27
79 71 64 87 21
10 73 1 40 9
36 84 80 6 60
19 81 55 50 56
67 23 62 86 63
87 45 56 67 13
8 79 31 48 86
32 15 88 6 66
62 27 44 26 99
64 63 3 70 90
84 87 89 71 2
63 67 72 3 75
39 44 54 20 85
1 97 14 37 98
25 66 92 17 57
27 34 64 60 87
77 29 21 56 23
79 53 75 72 69
95 16 85 52 70
92 65 62 33 15
42 87 96 79 90
97 77 58 62 55
11 86 68 44 52
93 23 1 61 60
47 72 14 28 13
14 78 68 48 74
50 32 29 24 54
73 99 57 90 64
12 76 62 15 44
70 58 22 1 85
49 2 75 88 87
71 61 95 5 38
99 86 67 8 83
17 11 9 54 33
70 78 62 1 58
11 44 53 73 13
45 95 15 63 49
94 34 99 64 10
78 9 67 12 20
50 97 96 89 14
55 3 72 93 81
25 43 60 85 26
96 45 53 19 40
73 42 76 47 80
74 69 22 23 89
24 59 62 91 5
51 75 76 29 35
86 96 94 66 55
87 61 82 40 32
28 22 27 21 49
66 80 82 46 13
97 67 41 63 1
65 89 22 12 15
94 96 9 91 48
85 3 60 95 8
57 90 97 56 33
79 15 75 70 41
21 26 20 98 81
18 36 24 76 35
42 27 11 67 0
89 31 86 10 13
81 8 16 0 77
92 67 39 96 74
90 7 75 55 65
51 2 97 58 17
92 55 4 83 93
31 21 74 73 68
18 41 32 17 77
56 94 98 72 87
19 6 49 11 37
15 79 24 60 91
25 41 63 32 56
13 83 69 0 57
77 7 62 45 98
64 37 94 55 9
81 42 29 98 44
16 83 27 92 60
22 63 79 64 45
80 38 56 5 2
0 4 34 37 59
90 85 32 97 52
69 37 57 29 51
22 4 99 67 84
0 2 76 34 47
63 96 94 83 40
72 68 70 40 39
22 7 62 46 76
25 31 41 71 9
30 52 78 26 10
53 17 45 16 98
66 39 96 16 67
46 34 27 49 2
93 25 50 70 57
33 69 64 30 45
10 91 20 18 3
32 35 71 62 43
24 57 46 39 87
28 21 26 31 52
99 60 14 6 97
1 44 89 33 93
47 15 21 23 20
4 50 6 93 44
38 53 2 45 42
83 57 63 17 24
99 5 34 66 0
65 91 60 50 62
16 2 51 14 32
81 17 58 59 77
29 98 72 28 3
15 99 49 37 5
62 23 48 80 28
68 2 71 89 36
13 95 64 98 8
60 86 51 74 11
35 27 66 78 7
65 9 57 85 30
29 52 27 83 98
7 48 45 21 93
5 71 54 34 91
96 87 25 84 63
38 94 65 69 18
79 81 80 36 91
17 2 23 53 98
92 68 21 74 55
3 58 72 70 86

View file

@ -0,0 +1,60 @@
--- Day 4: Giant Squid ---
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?
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?

500
day5/data/input.txt Normal file
View file

@ -0,0 +1,500 @@
35,968 -> 974,29
198,552 -> 124,478
731,697 -> 828,697
335,693 -> 335,699
936,853 -> 936,798
120,93 -> 798,93
150,334 -> 150,876
482,383 -> 388,383
983,262 -> 202,262
324,185 -> 473,334
403,500 -> 205,500
785,273 -> 200,273
415,48 -> 860,48
18,472 -> 125,365
198,878 -> 378,878
764,136 -> 764,421
295,476 -> 500,271
109,828 -> 109,675
219,302 -> 746,302
122,964 -> 122,977
191,96 -> 191,898
88,338 -> 88,679
966,116 -> 150,932
524,872 -> 423,771
504,373 -> 213,82
95,42 -> 552,499
33,135 -> 474,135
581,697 -> 938,340
450,138 -> 59,138
225,295 -> 746,295
68,27 -> 922,881
868,926 -> 868,928
403,257 -> 961,815
758,981 -> 289,512
22,968 -> 954,36
329,424 -> 200,295
123,783 -> 158,783
263,191 -> 263,813
11,946 -> 830,127
46,292 -> 830,292
323,977 -> 21,675
536,469 -> 186,469
831,16 -> 292,555
409,476 -> 409,209
500,870 -> 802,870
424,30 -> 424,599
956,275 -> 956,732
832,589 -> 353,589
963,648 -> 843,528
848,262 -> 887,262
726,874 -> 29,874
38,80 -> 599,641
808,210 -> 670,348
347,19 -> 727,19
679,811 -> 663,811
316,619 -> 540,843
360,631 -> 331,631
844,968 -> 577,701
64,622 -> 64,200
974,660 -> 332,18
795,11 -> 930,11
733,606 -> 733,17
878,519 -> 878,331
832,209 -> 603,209
577,572 -> 261,256
958,318 -> 479,797
723,177 -> 352,548
364,735 -> 364,143
26,982 -> 980,28
32,407 -> 276,407
192,312 -> 212,292
218,937 -> 916,239
314,185 -> 436,185
489,689 -> 691,689
964,280 -> 964,260
936,410 -> 175,410
900,182 -> 900,317
537,866 -> 537,351
584,330 -> 584,587
906,234 -> 632,234
274,986 -> 274,646
633,901 -> 430,901
973,66 -> 615,66
221,703 -> 221,868
562,658 -> 920,658
200,561 -> 200,277
265,517 -> 628,517
907,341 -> 907,199
942,16 -> 329,16
112,867 -> 947,32
858,464 -> 431,37
754,84 -> 754,976
954,629 -> 954,702
983,65 -> 90,958
522,904 -> 753,673
710,726 -> 129,726
175,48 -> 787,48
428,575 -> 808,195
283,814 -> 283,256
725,630 -> 725,590
984,242 -> 984,494
712,236 -> 712,818
186,802 -> 378,802
142,934 -> 984,934
144,661 -> 355,661
10,138 -> 834,962
812,707 -> 812,426
710,419 -> 710,367
577,398 -> 77,398
380,915 -> 380,120
653,799 -> 442,799
12,444 -> 879,444
821,138 -> 529,430
20,269 -> 528,777
774,404 -> 832,404
547,241 -> 368,420
744,701 -> 362,701
807,730 -> 60,730
58,954 -> 58,925
926,367 -> 677,367
443,894 -> 443,865
975,258 -> 975,285
506,296 -> 703,296
654,94 -> 76,94
451,700 -> 297,546
284,237 -> 840,237
763,724 -> 150,111
47,819 -> 47,69
935,53 -> 818,53
824,369 -> 547,369
297,326 -> 297,179
535,973 -> 628,973
780,834 -> 245,834
132,548 -> 988,548
634,606 -> 949,606
385,87 -> 385,92
107,553 -> 107,468
537,275 -> 537,413
100,18 -> 57,61
360,512 -> 360,584
363,339 -> 22,339
666,785 -> 661,785
570,323 -> 570,838
639,38 -> 399,38
647,950 -> 218,521
104,768 -> 104,968
975,261 -> 44,261
898,460 -> 391,460
212,883 -> 212,65
430,886 -> 430,818
157,568 -> 157,685
659,111 -> 712,111
498,298 -> 59,298
750,548 -> 135,548
383,742 -> 383,17
776,525 -> 776,623
143,930 -> 143,291
101,559 -> 774,559
473,99 -> 368,204
564,898 -> 343,677
381,935 -> 27,581
814,618 -> 814,811
760,581 -> 760,876
961,238 -> 240,959
383,133 -> 383,503
691,442 -> 616,442
490,240 -> 236,494
327,724 -> 769,724
60,251 -> 986,251
416,680 -> 580,844
691,825 -> 944,825
148,72 -> 148,276
574,482 -> 574,313
296,327 -> 296,391
226,521 -> 226,396
757,741 -> 932,741
332,678 -> 226,678
687,147 -> 576,147
730,405 -> 730,564
629,354 -> 629,39
989,988 -> 11,10
208,393 -> 208,608
516,301 -> 305,512
946,633 -> 946,552
820,16 -> 820,337
717,136 -> 717,117
761,951 -> 761,117
34,797 -> 773,58
11,41 -> 947,977
328,561 -> 464,561
279,400 -> 913,400
203,952 -> 964,191
829,673 -> 474,673
144,898 -> 461,581
423,892 -> 203,892
501,865 -> 97,865
640,111 -> 640,108
297,57 -> 624,384
656,441 -> 656,757
930,980 -> 930,974
605,579 -> 827,579
149,178 -> 149,886
694,797 -> 694,133
261,219 -> 261,263
823,810 -> 32,19
74,168 -> 718,812
667,501 -> 873,501
726,681 -> 223,681
708,78 -> 140,78
19,804 -> 749,804
508,900 -> 508,957
553,545 -> 245,237
469,86 -> 702,86
157,92 -> 157,693
480,834 -> 824,834
249,639 -> 471,639
863,852 -> 337,852
865,886 -> 256,277
257,225 -> 310,225
114,632 -> 114,446
735,859 -> 36,859
117,357 -> 117,108
952,976 -> 185,976
885,539 -> 885,970
547,86 -> 974,513
69,763 -> 69,21
790,857 -> 282,349
81,953 -> 972,62
135,138 -> 135,112
30,449 -> 310,169
954,11 -> 18,947
945,60 -> 20,985
59,341 -> 544,341
393,648 -> 955,648
622,600 -> 312,290
279,272 -> 279,876
14,870 -> 874,10
798,514 -> 798,487
948,961 -> 11,24
80,333 -> 237,490
23,218 -> 23,117
895,199 -> 980,199
800,116 -> 615,116
602,740 -> 759,740
989,397 -> 780,188
666,164 -> 666,798
418,447 -> 507,536
513,665 -> 649,665
78,56 -> 602,580
849,780 -> 849,588
158,900 -> 941,117
586,283 -> 586,660
718,954 -> 422,954
774,191 -> 139,826
207,733 -> 207,284
974,19 -> 14,979
729,41 -> 729,97
28,971 -> 943,56
166,44 -> 882,760
533,255 -> 65,255
175,228 -> 175,966
420,245 -> 420,498
885,111 -> 117,879
112,140 -> 925,953
777,426 -> 925,278
22,596 -> 22,952
718,570 -> 87,570
196,204 -> 68,204
372,456 -> 372,494
825,876 -> 156,207
568,25 -> 286,25
839,950 -> 247,950
435,76 -> 421,76
746,550 -> 294,550
900,178 -> 900,453
228,209 -> 900,209
762,363 -> 613,363
156,298 -> 156,528
267,536 -> 267,436
433,300 -> 954,300
596,586 -> 596,659
147,390 -> 845,390
803,89 -> 295,597
841,57 -> 101,57
74,36 -> 696,658
546,452 -> 919,825
330,575 -> 862,43
575,689 -> 868,982
356,649 -> 356,600
893,27 -> 168,752
248,479 -> 547,479
804,631 -> 804,192
230,903 -> 230,454
501,675 -> 487,675
943,61 -> 117,887
43,866 -> 43,278
83,90 -> 723,730
103,824 -> 103,143
496,775 -> 496,768
638,237 -> 638,112
614,632 -> 184,632
476,810 -> 358,810
174,909 -> 715,368
676,555 -> 16,555
34,928 -> 34,854
187,90 -> 110,167
467,438 -> 372,533
218,726 -> 326,726
927,58 -> 468,517
754,746 -> 754,900
613,705 -> 613,712
423,440 -> 423,422
291,657 -> 680,268
286,989 -> 286,479
959,720 -> 959,648
577,571 -> 355,571
208,145 -> 982,919
957,19 -> 957,363
576,253 -> 576,192
528,262 -> 22,262
945,352 -> 914,352
978,746 -> 737,746
613,279 -> 17,875
586,370 -> 768,370
462,403 -> 462,451
322,526 -> 322,973
873,104 -> 75,902
314,505 -> 689,130
817,657 -> 813,657
812,88 -> 775,51
639,91 -> 639,489
541,430 -> 541,346
318,176 -> 702,176
375,821 -> 279,821
982,975 -> 21,14
958,965 -> 54,61
307,124 -> 539,124
236,879 -> 581,879
109,942 -> 688,942
36,863 -> 786,113
54,739 -> 54,837
710,131 -> 27,131
945,45 -> 10,980
859,295 -> 859,610
853,916 -> 853,44
123,421 -> 711,421
605,817 -> 666,817
328,934 -> 308,954
566,644 -> 798,644
229,861 -> 217,861
155,263 -> 155,830
369,813 -> 369,337
857,61 -> 517,61
111,597 -> 382,326
279,478 -> 899,478
937,709 -> 288,60
686,258 -> 979,258
775,511 -> 907,511
594,518 -> 105,29
524,443 -> 171,443
250,861 -> 373,861
508,645 -> 952,645
473,299 -> 767,299
339,637 -> 734,242
602,488 -> 941,149
577,514 -> 577,494
30,107 -> 207,107
973,911 -> 973,277
212,629 -> 674,167
37,887 -> 37,517
135,783 -> 322,783
747,851 -> 216,320
794,317 -> 794,756
67,908 -> 162,908
476,278 -> 809,278
327,503 -> 327,751
906,76 -> 58,924
509,962 -> 43,496
122,678 -> 582,218
683,969 -> 431,969
804,740 -> 804,932
680,192 -> 259,192
502,928 -> 195,621
164,68 -> 978,882
432,738 -> 430,740
947,809 -> 947,937
383,502 -> 383,933
966,577 -> 929,577
571,793 -> 486,793
990,143 -> 803,143
509,781 -> 509,563
80,803 -> 80,347
542,612 -> 143,612
218,787 -> 218,100
724,842 -> 476,594
168,19 -> 885,19
163,134 -> 163,617
313,706 -> 462,855
289,250 -> 867,828
639,677 -> 854,677
590,245 -> 16,819
567,158 -> 567,868
205,813 -> 89,813
944,132 -> 125,951
365,726 -> 917,174
978,978 -> 15,15
124,368 -> 54,368
61,905 -> 826,140
279,618 -> 616,281
554,412 -> 125,841
28,173 -> 712,857
155,971 -> 803,323
204,214 -> 748,214
778,473 -> 778,239
58,219 -> 792,219
898,70 -> 64,904
834,675 -> 658,675
114,870 -> 114,226
845,618 -> 845,194
541,137 -> 323,355
51,849 -> 164,849
223,70 -> 223,855
295,30 -> 295,191
763,316 -> 67,316
793,460 -> 186,460
10,149 -> 834,973
722,972 -> 183,433
693,681 -> 974,681
398,486 -> 846,38
534,774 -> 609,774
69,899 -> 606,899
903,682 -> 493,682
490,380 -> 490,203
845,877 -> 845,464
93,349 -> 617,349
810,526 -> 810,422
178,374 -> 178,161
49,377 -> 49,693
566,542 -> 79,542
866,438 -> 866,518
966,762 -> 540,336
949,276 -> 190,276
161,326 -> 827,326
962,576 -> 750,576
218,217 -> 218,411
606,879 -> 606,470
855,791 -> 571,507
425,301 -> 937,301
920,174 -> 125,969
498,943 -> 498,982
744,717 -> 744,976
660,134 -> 834,134
942,481 -> 942,134
759,461 -> 759,556
255,690 -> 255,984
436,754 -> 967,223
659,429 -> 695,429
256,166 -> 256,506
91,405 -> 804,405
211,869 -> 245,903
986,886 -> 986,216
337,603 -> 337,988
388,631 -> 230,473
86,324 -> 448,686
626,168 -> 626,702
542,849 -> 681,988
824,454 -> 667,611
962,352 -> 962,705
463,168 -> 463,985
226,808 -> 467,808
555,649 -> 56,649
804,75 -> 74,805
583,793 -> 583,274
933,106 -> 123,916
563,842 -> 294,573
50,601 -> 518,601
140,669 -> 100,669
930,542 -> 930,393
954,650 -> 262,650
56,295 -> 708,947
43,565 -> 303,305
183,470 -> 34,470
151,519 -> 83,519
727,594 -> 727,129
561,620 -> 561,311
985,94 -> 985,473
11,63 -> 934,986
293,924 -> 162,924
741,780 -> 549,972
65,561 -> 65,722
903,447 -> 542,808
13,350 -> 13,564
838,661 -> 838,248
94,434 -> 65,434
870,839 -> 870,933
982,528 -> 982,262
816,693 -> 816,521
685,645 -> 448,645
707,579 -> 163,35
330,313 -> 151,313

View file

@ -0,0 +1,43 @@
--- Day 5: Hydrothermal Venture ---
You come across a field of hydrothermal vents on the ocean floor! These vents constantly produce large, opaque clouds, so it would be best to avoid them if possible.
They tend to form in lines; the submarine helpfully produces a list of nearby lines of vents (your puzzle input) for you to review. For example:
0,9 -> 5,9
8,0 -> 0,8
9,4 -> 3,4
2,2 -> 2,1
7,0 -> 7,4
6,4 -> 2,0
0,9 -> 2,9
3,4 -> 1,4
0,0 -> 8,8
5,5 -> 8,2
Each line of vents is given as a line segment in the format x1,y1 -> x2,y2 where x1,y1 are the coordinates of one end the line segment and x2,y2 are the coordinates of the other end. These line segments include the points at both ends. In other words:
An entry like 1,1 -> 1,3 covers points 1,1, 1,2, and 1,3.
An entry like 9,7 -> 7,7 covers points 9,7, 8,7, and 7,7.
For now, only consider horizontal and vertical lines: lines where either x1 = x2 or y1 = y2.
So, the horizontal and vertical lines from the above list would produce the following diagram:
.......1..
..1....1..
..1....1..
.......1..
.112111211
..........
..........
..........
..........
222111....
In this diagram, the top left corner is 0,0 and the bottom right corner is 9,9. Each position is shown as the number of lines which cover that point or . if no line covers that point. The top-left pair of 1s, for example, comes from 2,2 -> 2,1; the very bottom row is formed by the overlapping lines 0,9 -> 5,9 and 0,9 -> 2,9.
To avoid the most dangerous areas, you need to determine the number of points where at least two lines overlap. In the above example, this is anywhere in the diagram with a 2 or larger - a total of 5 points.
Consider only horizontal and vertical lines. At how many points do at least two lines overlap?

2
day6/data/input.txt Normal file
View file

@ -0,0 +1,2 @@
4,1,1,4,1,2,1,4,1,3,4,4,1,5,5,1,3,1,1,1,4,4,3,1,5,3,1,2,5,1,1,5,1,1,4,1,1,1,1,2,1,5,3,4,4,1,1,1,1,1,1,1,1,1,2,1,1,1,1,1,5,1,1,1,4,1,2,3,5,1,2,2,4,1,4,4,4,1,2,5,1,2,1,1,1,1,1,1,4,1,1,4,3,4,2,1,3,1,1,1,3,5,5,4,3,4,1,5,1,1,1,2,2,1,3,1,2,4,1,1,3,3,1,3,3,1,1,3,1,5,1,1,3,1,1,1,5,4,1,1,1,1,4,1,1,3,5,4,3,1,1,5,4,1,1,2,5,4,2,1,4,1,1,1,1,3,1,1,1,1,4,1,1,1,1,2,4,1,1,1,1,3,1,1,5,1,1,1,1,1,1,4,2,1,3,1,1,1,2,4,2,3,1,4,1,2,1,4,2,1,4,4,1,5,1,1,4,4,1,2,2,1,1,1,1,1,1,1,1,1,1,1,4,5,4,1,3,1,3,1,1,1,5,3,5,5,2,2,1,4,1,4,2,1,4,1,2,1,1,2,1,1,5,4,2,1,1,1,2,4,1,1,1,1,2,1,1,5,1,1,2,2,5,1,1,1,1,1,2,4,2,3,1,2,1,5,4,5,1,4

View file

@ -0,0 +1,54 @@
y 6: Lanternfish ---
The sea floor is getting steeper. Maybe the sleigh keys got carried this way?
A massive school of glowing 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, each lanternfish creates a new lanternfish 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?

2
day7/data/input.txt Normal file
View file

@ -0,0 +1,2 @@
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,485,546,350,100,791,199,115,144,649,41,1656,163,903,71,384,30,2,251,554,210,434,206,546,759,258,54,1478,48,438,601,326,5,1017,165,168,201,622,864,1338,24,1074,545,499,484,264,345,332,869,297,711,674,346,1139,317,875,242,725,250,1619,1408,956,380,366,187,1034,1555,467,170,114,1136,150,183,304,44,37,333,791,34,540,716,1923,342,6,922,18,24,1189,59,1726,636,442,426,1089,526,298,386,296,623,80,272,240,406,628,238,409,302,35,404,92,48,157,1545,409,1382,151,1656,3,76,14,115,566,650,197,448,573,161,86,140,875,128,319,4,822,530,189,247,667,82,316,274,110,206,1012,166,639,579,459,284,200,16,24,147,743,113,1562,387,60,84,797,14,30,1015,508,88,113,685,658,257,1507,348,30,808,416,9,835,671,16,474,885,230,47,463,1324,1263,183,603,739,0,296,789,1411,339,27,1154,31,882,409,646,92,153,147,974,497,308,85,311,135,627,811,295,698,2,20,1170,789,702,1194,1390,432,257,715,958,150,1295,144,1193,607,67,929,383,1051,1231,393,190,380,1203,1090,1238,143,206,210,1004,304,1305,392,143,1379,665,806,452,185,4,1,201,1104,633,274,493,472,141,674,1261,106,587,244,903,91,158,69,137,922,778,143,692,160,474,7,304,824,657,15,1110,806,295,1565,1162,358,725,877,440,690,13,69,111,304,300,493,249,105,746,20,163,561,913,558,252,13,193,508,12,845,120,205,154,1582,349,1471,529,268,23,689,6,776,565,401,0,623,186,62,95,148,275,1,137,320,0,19,1803,10,100,652,750,226,484,180,46,310,446,667,543,277,139,265,74,171,87,1753,337,162,59,1339,1040,1287,1084,192,169,50,1557,81,1120,271,167,977,76,295,12,54,710,36,364,521,989,1634,720,1031,1204,355,380,859,633,223,1207,221,31,138,1305,779,1026,52,92,216,221,0,980,130,1197,585,1213,63,157,213,993,1123,588,450,256,1021,90,1420,47,386,843,1188,1466,807,596,416,23,32,62,1289,317,368,491,907,1386,114,1620,39,344,1342,43,281,12,1202,257,1357,203,465,174,350,833,125,54,390,687,339,628,819,261,1341,840,643,414,82,373,428,1315,570,1070,686,893,70,728,70,358,1233,189,1247,244,1043,1135,42,531,962,35,30,1462,946,856,145,386,1134,1071,379,740,175,1205,234,354,5,1028,506,58,433,1055,749,854,99,298,1248,619,62,181,258,42,130,1698,1313,672,129,222,127,636,846,24,1324,946,622,689,168,329,301,458,173,591,772,93,282,8,320,106,233,412,556,2,522,369,8,1371,899,503,568,667,1199,92,115,899,952,81,629,175,274,763,204,339,236,317,257,731,1082,1724,211,516,165,91,334,1216,101,21,1340,235,336,1351,723,1745,183,841,104,172,1080,180,493,798,1468,45,1627,59,58,368,560,166,1125,136,26,1238,1580,420,1732,155,55,293,751,194,1723,175,11,30,10,307,57,66,704,285,685,241,565,368,50,181,1047,147,420,1341,20,37,400,798,476,1060,642,134,140,502,254,997,910,636,179,22,612,55,237,258,48,205,412,155,910,192,262,9,91,766,1426,71,5,315,285,186,629,422,1289,397,52,860,1390,106,887,1285,1196,684,36,703,199,4,277,151,82,293,1047,455,21,935,630,736,118,13,30,584,453,1446,381,585,810,177,1028,280,281,184,78,673,126,410,872,524,78,188,121,394,201,1764,609,350,706,428,88,783,189,643,305,516,259,582,309,985,338,21,235,73,44,585,71,983,175,1336,1056,10,8,537,701,1653,657,70,1242,442,52,973,203,173,959,964,272,348,3,567,714,1466,382,129,613,1042,686,461,57,523,740,726,149,1490,867,44,379,1270,547,649,1103,912,1354,985,458,887,603,1016,317,499,690,829,1231,364,772,29,57,357,467,484,202,150,109,95,414,444,383,62,124,645,723,772,881,1553,413,123,248,1085,453,260,214,113,1874,482,942,235,899,122,171,127,913,424,406,49,97,1848,295,1152,111,350,54,1160,2,16,156,448,394,740,49,1237,548,206,1206,775,748,728,48,238,148,109,18,56,64,515,163,609,273,301,396,207,51,478,1183,864,772,450,222,1387,269,40,87,426,164,1270,21,347,316,331,408,914,1046,173,48,398,177,431,47,1055,221,513,226,84,285,566,270,333,343,480,1802,101,683,168,1347,582,80,22,329,350,108,379,14,53,349,43,435,195,102,168,338

View file

@ -0,0 +1,35 @@
--- Day 7: The Treachery of Whales ---
A giant 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?