Add problem texts
This commit is contained in:
parent
e1e50de4e3
commit
43356e90d8
21 changed files with 2546 additions and 76 deletions
87
01/problem.html
Normal file
87
01/problem.html
Normal file
|
@ -0,0 +1,87 @@
|
|||
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, text/html, charset=UTF-8" http-equiv="Content-Type">
|
||||
</meta>
|
||||
<title>Day 1 - Advent of Code 2021</title>
|
||||
<style type="text/css">
|
||||
body {
|
||||
margin: 30px auto;
|
||||
max-width: 650px;
|
||||
line-height: 1.4;
|
||||
padding: 0 10px;
|
||||
}
|
||||
h1, h2, h3 {
|
||||
line-height: 1.2;
|
||||
}
|
||||
</style>
|
||||
</head><div id="readability-page-1" class="page"><div>
|
||||
|
||||
<article><h2>--- Day 1: Sonar Sweep ---</h2><p>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!</p>
|
||||
<p>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 <em>stars</em>.</p>
|
||||
<p>Your instincts tell you that in order to save Christmas, you'll need to get all <em>fifty stars</em> by December 25th.</p>
|
||||
<p>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 <em>one star</em>. Good luck!</p>
|
||||
<p>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.</p>
|
||||
<p>For example, suppose you had the following report:</p>
|
||||
<pre><code>199
|
||||
200
|
||||
208
|
||||
210
|
||||
200
|
||||
207
|
||||
240
|
||||
269
|
||||
260
|
||||
263
|
||||
</code></pre>
|
||||
<p>This report indicates that, scanning outward from the submarine, the sonar sweep found depths of <code>199</code>, <code>200</code>, <code>208</code>, <code>210</code>, and so on.</p>
|
||||
<p>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.</p>
|
||||
<p>To do this, count <em>the number of times a depth measurement increases</em> from the previous measurement. (There is no measurement before the first measurement.) In the example above, the changes are as follows:</p>
|
||||
<pre><code>199 (N/A - no previous measurement)
|
||||
200 (<em>increased</em>)
|
||||
208 (<em>increased</em>)
|
||||
210 (<em>increased</em>)
|
||||
200 (decreased)
|
||||
207 (<em>increased</em>)
|
||||
240 (<em>increased</em>)
|
||||
269 (<em>increased</em>)
|
||||
260 (decreased)
|
||||
263 (<em>increased</em>)
|
||||
</code></pre>
|
||||
<p>In this example, there are <em><code>7</code></em> measurements that are larger than the previous measurement.</p>
|
||||
<p><em>How many measurements are larger than the previous measurement?</em></p>
|
||||
</article>
|
||||
<p>Your puzzle answer was <code>1754</code>.</p><article><h2 id="part2">--- Part Two ---</h2><p>Considering every single measurement isn't as useful as you expected: there's just too much noise in the data.</p>
|
||||
<p>Instead, consider sums of a <em>three-measurement sliding window</em>. Again considering the above example:</p>
|
||||
<pre><code>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
|
||||
</code></pre>
|
||||
<p>Start by comparing the first and second three-measurement windows. The measurements in the first window are marked <code>A</code> (<code>199</code>, <code>200</code>, <code>208</code>); their sum is <code>199 + 200 + 208 = 607</code>. The second window is marked <code>B</code> (<code>200</code>, <code>208</code>, <code>210</code>); its sum is <code>618</code>. The sum of measurements in the second window is larger than the sum of the first, so this first comparison <em>increased</em>.</p>
|
||||
<p>Your goal now is to count <em>the number of times the sum of measurements in this sliding window increases</em> from the previous sum. So, compare <code>A</code> with <code>B</code>, then compare <code>B</code> with <code>C</code>, then <code>C</code> with <code>D</code>, and so on. Stop when there aren't enough measurements left to create a new three-measurement sum.</p>
|
||||
<p>In the above example, the sum of each three-measurement window is as follows:</p>
|
||||
<pre><code>A: 607 (N/A - no previous sum)
|
||||
B: 618 (<em>increased</em>)
|
||||
C: 618 (no change)
|
||||
D: 617 (decreased)
|
||||
E: 647 (<em>increased</em>)
|
||||
F: 716 (<em>increased</em>)
|
||||
G: 769 (<em>increased</em>)
|
||||
H: 792 (<em>increased</em>)
|
||||
</code></pre>
|
||||
<p>In this example, there are <em><code>5</code></em> sums that are larger than the previous sum.</p>
|
||||
<p>Consider sums of a three-measurement sliding window. <em>How many sums are larger than the previous sum?</em></p>
|
||||
</article>
|
||||
<p>Your puzzle answer was <code>1789</code>.</p><p>Both parts of this puzzle are complete! They provide two gold stars: **</p>
|
||||
<p>At this point, you should <a href="https://adventofcode.com/2021">return to your Advent calendar</a> and try another puzzle.</p>
|
||||
<p>If you still want to see it, you can <a href="https://adventofcode.com/2021/day/1/input" target="_blank">get your puzzle input</a>.</p>
|
||||
<p>You can also this puzzle.</p>
|
||||
</div></div>
|
|
@ -1,76 +0,0 @@
|
|||
--- 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?
|
||||
|
||||
--- 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?
|
76
02/problem.html
Normal file
76
02/problem.html
Normal file
|
@ -0,0 +1,76 @@
|
|||
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, text/html, charset=UTF-8" http-equiv="Content-Type">
|
||||
</meta>
|
||||
<title>Day 2 - Advent of Code 2021</title>
|
||||
<style type="text/css">
|
||||
body {
|
||||
margin: 30px auto;
|
||||
max-width: 650px;
|
||||
line-height: 1.4;
|
||||
padding: 0 10px;
|
||||
}
|
||||
h1, h2, h3 {
|
||||
line-height: 1.2;
|
||||
}
|
||||
</style>
|
||||
</head><div id="readability-page-1" class="page"><div>
|
||||
|
||||
<article><h2>--- Day 2: Dive! ---</h2><p>Now, you need to figure out how to <span title="Tank, I need a pilot program for a B212 helicopter.">pilot this thing</span>.</p>
|
||||
<p>It seems like the submarine can take a series of commands like <code>forward 1</code>, <code>down 2</code>, or <code>up 3</code>:</p>
|
||||
<ul>
|
||||
<li><code>forward X</code> increases the horizontal position by <code>X</code> units.</li>
|
||||
<li><code>down X</code> <em>increases</em> the depth by <code>X</code> units.</li>
|
||||
<li><code>up X</code> <em>decreases</em> the depth by <code>X</code> units.</li>
|
||||
</ul>
|
||||
<p>Note that since you're on a submarine, <code>down</code> and <code>up</code> affect your <em>depth</em>, and so they have the opposite result of what you might expect.</p>
|
||||
<p>The submarine seems to already have a planned course (your puzzle input). You should probably figure out where it's going. For example:</p>
|
||||
<pre><code>forward 5
|
||||
down 5
|
||||
forward 8
|
||||
up 3
|
||||
down 8
|
||||
forward 2
|
||||
</code></pre>
|
||||
<p>Your horizontal position and depth both start at <code>0</code>. The steps above would then modify them as follows:</p>
|
||||
<ul>
|
||||
<li><code>forward 5</code> adds <code>5</code> to your horizontal position, a total of <code>5</code>.</li>
|
||||
<li><code>down 5</code> adds <code>5</code> to your depth, resulting in a value of <code>5</code>.</li>
|
||||
<li><code>forward 8</code> adds <code>8</code> to your horizontal position, a total of <code>13</code>.</li>
|
||||
<li><code>up 3</code> decreases your depth by <code>3</code>, resulting in a value of <code>2</code>.</li>
|
||||
<li><code>down 8</code> adds <code>8</code> to your depth, resulting in a value of <code>10</code>.</li>
|
||||
<li><code>forward 2</code> adds <code>2</code> to your horizontal position, a total of <code>15</code>.</li>
|
||||
</ul>
|
||||
<p>After following these instructions, you would have a horizontal position of <code>15</code> and a depth of <code>10</code>. (Multiplying these together produces <code><em>150</em></code>.)</p>
|
||||
<p>Calculate the horizontal position and depth you would have after following the planned course. <em>What do you get if you multiply your final horizontal position by your final depth?</em></p>
|
||||
</article>
|
||||
<p>Your puzzle answer was <code>1727835</code>.</p><article><h2 id="part2">--- Part Two ---</h2><p>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.</p>
|
||||
<p>In addition to horizontal position and depth, you'll also need to track a third value, <em>aim</em>, which also starts at <code>0</code>. The commands also mean something entirely different than you first thought:</p>
|
||||
<ul>
|
||||
<li><code>down X</code> <em>increases</em> your aim by <code>X</code> units.</li>
|
||||
<li><code>up X</code> <em>decreases</em> your aim by <code>X</code> units.</li>
|
||||
<li><code>forward X</code> does two things:<ul>
|
||||
<li>It increases your horizontal position by <code>X</code> units.</li>
|
||||
<li>It increases your depth by your aim <em>multiplied by</em> <code>X</code>.</li>
|
||||
</ul></li>
|
||||
</ul>
|
||||
<p>Again note that since you're on a submarine, <code>down</code> and <code>up</code> do the opposite of what you might expect: "down" means aiming in the positive direction.</p>
|
||||
<p>Now, the above example does something different:</p>
|
||||
<ul>
|
||||
<li><code>forward 5</code> adds <code>5</code> to your horizontal position, a total of <code>5</code>. Because your aim is <code>0</code>, your depth does not change.</li>
|
||||
<li><code>down 5</code> adds <code>5</code> to your aim, resulting in a value of <code>5</code>.</li>
|
||||
<li><code>forward 8</code> adds <code>8</code> to your horizontal position, a total of <code>13</code>. Because your aim is <code>5</code>, your depth increases by <code>8*5=40</code>.</li>
|
||||
<li><code>up 3</code> decreases your aim by <code>3</code>, resulting in a value of <code>2</code>.</li>
|
||||
<li><code>down 8</code> adds <code>8</code> to your aim, resulting in a value of <code>10</code>.</li>
|
||||
<li><code>forward 2</code> adds <code>2</code> to your horizontal position, a total of <code>15</code>. Because your aim is <code>10</code>, your depth increases by <code>2*10=20</code> to a total of <code>60</code>.</li>
|
||||
</ul>
|
||||
<p>After following these new instructions, you would have a horizontal position of <code>15</code> and a depth of <code>60</code>. (Multiplying these produces <code><em>900</em></code>.)</p>
|
||||
<p>Using this new interpretation of the commands, calculate the horizontal position and depth you would have after following the planned course. <em>What do you get if you multiply your final horizontal position by your final depth?</em></p>
|
||||
</article>
|
||||
<p>Your puzzle answer was <code>1544000595</code>.</p><p>Both parts of this puzzle are complete! They provide two gold stars: **</p>
|
||||
<p>At this point, you should <a href="https://adventofcode.com/2021">return to your Advent calendar</a> and try another puzzle.</p>
|
||||
<p>If you still want to see it, you can <a href="https://adventofcode.com/2021/day/2/input" target="_blank">get your puzzle input</a>.</p>
|
||||
<p>You can also this puzzle.</p>
|
||||
</div></div>
|
72
03/problem.html
Normal file
72
03/problem.html
Normal file
|
@ -0,0 +1,72 @@
|
|||
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, text/html, charset=UTF-8" http-equiv="Content-Type">
|
||||
</meta>
|
||||
<title>Day 3 - Advent of Code 2021</title>
|
||||
<style type="text/css">
|
||||
body {
|
||||
margin: 30px auto;
|
||||
max-width: 650px;
|
||||
line-height: 1.4;
|
||||
padding: 0 10px;
|
||||
}
|
||||
h1, h2, h3 {
|
||||
line-height: 1.2;
|
||||
}
|
||||
</style>
|
||||
</head><div id="readability-page-1" class="page"><article><h2>--- Day 3: Binary Diagnostic ---</h2><p>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.</p>
|
||||
<p>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 <em>power consumption</em>.</p>
|
||||
<p>You need to use the binary numbers in the diagnostic report to generate two new binary numbers (called the <em>gamma rate</em> and the <em>epsilon rate</em>). The power consumption can then be found by multiplying the gamma rate by the epsilon rate.</p>
|
||||
<p>Each bit in the gamma rate can be determined by finding the <em>most common bit in the corresponding position</em> of all numbers in the diagnostic report. For example, given the following diagnostic report:</p>
|
||||
<pre><code>00100
|
||||
11110
|
||||
10110
|
||||
10111
|
||||
10101
|
||||
01111
|
||||
00111
|
||||
11100
|
||||
10000
|
||||
11001
|
||||
00010
|
||||
01010
|
||||
</code></pre>
|
||||
<p>Considering only the first bit of each number, there are five <code>0</code> bits and seven <code>1</code> bits. Since the most common bit is <code>1</code>, the first bit of the gamma rate is <code>1</code>.</p>
|
||||
<p>The most common second bit of the numbers in the diagnostic report is <code>0</code>, so the second bit of the gamma rate is <code>0</code>.</p>
|
||||
<p>The most common value of the third, fourth, and fifth bits are <code>1</code>, <code>1</code>, and <code>0</code>, respectively, and so the final three bits of the gamma rate are <code>110</code>.</p>
|
||||
<p>So, the gamma rate is the binary number <code>10110</code>, or <code><em>22</em></code> in decimal.</p>
|
||||
<p>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 <code>01001</code>, or <code><em>9</em></code> in decimal. Multiplying the gamma rate (<code>22</code>) by the epsilon rate (<code>9</code>) produces the power consumption, <code><em>198</em></code>.</p>
|
||||
<p>Use the binary numbers in your diagnostic report to calculate the gamma rate and epsilon rate, then multiply them together. <em>What is the power consumption of the submarine?</em> (Be sure to represent your answer in decimal, not binary.)</p>
|
||||
</article><p>Your puzzle answer was <code>4006064</code>.</p><article><h2 id="part2">--- Part Two ---</h2><p>Next, you should verify the <em>life support rating</em>, which can be determined by multiplying the <em>oxygen generator rating</em> by the <em>CO2 scrubber rating</em>.</p>
|
||||
<p>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 <em>consider just the first bit</em> of those numbers. Then:</p>
|
||||
<ul>
|
||||
<li>Keep only numbers selected by the <em>bit criteria</em> for the type of rating value for which you are searching. Discard numbers which do not match the bit criteria.</li>
|
||||
<li>If you only have one number left, stop; this is the rating value for which you are searching.</li>
|
||||
<li>Otherwise, repeat the process, considering the next bit to the right.</li>
|
||||
</ul>
|
||||
<p>The <em>bit criteria</em> depends on which type of rating value you want to find:</p>
|
||||
<ul>
|
||||
<li>To find <em>oxygen generator rating</em>, determine the <em>most common</em> value (<code>0</code> or <code>1</code>) in the current bit position, and keep only numbers with that bit in that position. If <code>0</code> and <code>1</code> are equally common, keep values with a <code><em>1</em></code> in the position being considered.</li>
|
||||
<li>To find <em>CO2 scrubber rating</em>, determine the <em>least common</em> value (<code>0</code> or <code>1</code>) in the current bit position, and keep only numbers with that bit in that position. If <code>0</code> and <code>1</code> are equally common, keep values with a <code><em>0</em></code> in the position being considered.</li>
|
||||
</ul>
|
||||
<p>For example, to determine the <em>oxygen generator rating</em> value using the same example diagnostic report from above:</p>
|
||||
<ul>
|
||||
<li>Start with all 12 numbers and consider only the first bit of each number. There are more <code>1</code> bits (7) than <code>0</code> bits (5), so keep only the 7 numbers with a <code>1</code> in the first position: <code>11110</code>, <code>10110</code>, <code>10111</code>, <code>10101</code>, <code>11100</code>, <code>10000</code>, and <code>11001</code>.</li>
|
||||
<li>Then, consider the second bit of the 7 remaining numbers: there are more <code>0</code> bits (4) than <code>1</code> bits (3), so keep only the 4 numbers with a <code>0</code> in the second position: <code>10110</code>, <code>10111</code>, <code>10101</code>, and <code>10000</code>.</li>
|
||||
<li>In the third position, three of the four numbers have a <code>1</code>, so keep those three: <code>10110</code>, <code>10111</code>, and <code>10101</code>.</li>
|
||||
<li>In the fourth position, two of the three numbers have a <code>1</code>, so keep those two: <code>10110</code> and <code>10111</code>.</li>
|
||||
<li>In the fifth position, there are an equal number of <code>0</code> bits and <code>1</code> bits (one each). So, to find the <em>oxygen generator rating</em>, keep the number with a <code>1</code> in that position: <code>10111</code>.</li>
|
||||
<li>As there is only one number left, stop; the <em>oxygen generator rating</em> is <code>10111</code>, or <code><em>23</em></code> in decimal.</li>
|
||||
</ul>
|
||||
<p>Then, to determine the <em>CO2 scrubber rating</em> value from the same example above:</p>
|
||||
<ul>
|
||||
<li>Start again with all 12 numbers and consider only the first bit of each number. There are fewer <code>0</code> bits (5) than <code>1</code> bits (7), so keep only the 5 numbers with a <code>0</code> in the first position: <code>00100</code>, <code>01111</code>, <code>00111</code>, <code>00010</code>, and <code>01010</code>.</li>
|
||||
<li>Then, consider the second bit of the 5 remaining numbers: there are fewer <code>1</code> bits (2) than <code>0</code> bits (3), so keep only the 2 numbers with a <code>1</code> in the second position: <code>01111</code> and <code>01010</code>.</li>
|
||||
<li>In the third position, there are an equal number of <code>0</code> bits and <code>1</code> bits (one each). So, to find the <em>CO2 scrubber rating</em>, keep the number with a <code>0</code> in that position: <code>01010</code>.</li>
|
||||
<li>As there is only one number left, stop; the <em>CO2 scrubber rating</em> is <code>01010</code>, or <code><em>10</em></code> in decimal.</li>
|
||||
</ul>
|
||||
<p>Finally, to find the life support rating, multiply the oxygen generator rating (<code>23</code>) by the CO2 scrubber rating (<code>10</code>) to get <code><em>230</em></code>.</p>
|
||||
<p>Use the binary numbers in your diagnostic report to calculate the oxygen generator rating and CO2 scrubber rating, then multiply them together. <em>What is the life support rating of the submarine?</em> (Be sure to represent your answer in decimal, not binary.)</p>
|
||||
</article><p>Your puzzle answer was <code>5941884</code>.</p></div>
|
71
04/problem.html
Normal file
71
04/problem.html
Normal file
|
@ -0,0 +1,71 @@
|
|||
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, text/html, charset=UTF-8" http-equiv="Content-Type">
|
||||
</meta>
|
||||
<title>Day 4 - Advent of Code 2021</title>
|
||||
<style type="text/css">
|
||||
body {
|
||||
margin: 30px auto;
|
||||
max-width: 650px;
|
||||
line-height: 1.4;
|
||||
padding: 0 10px;
|
||||
}
|
||||
h1, h2, h3 {
|
||||
line-height: 1.2;
|
||||
}
|
||||
</style>
|
||||
</head><div id="readability-page-1" class="page"><article><h2>--- Day 4: Giant Squid ---</h2><p>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 <em>can</em> see, however, is a giant squid that has attached itself to the outside of your submarine.</p>
|
||||
<p>Maybe it wants to play <a href="https://en.wikipedia.org/wiki/Bingo_(American_version)" target="_blank">bingo</a>?</p>
|
||||
<p>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 <em>marked</em> 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 <em>wins</em>. (Diagonals don't count.)</p>
|
||||
<p>The submarine has a <em>bingo subsystem</em> 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:</p>
|
||||
<pre><code>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
|
||||
</code></pre>
|
||||
<p>After the first five numbers are drawn (<code>7</code>, <code>4</code>, <code>9</code>, <code>5</code>, and <code>11</code>), there are no winners, but the boards are marked as follows (shown here adjacent to each other to save space):</p>
|
||||
<pre><code>22 13 17 <em>11</em> 0 3 15 0 2 22 14 21 17 24 <em>4</em>
|
||||
8 2 23 <em>4</em> 24 <em>9</em> 18 13 17 <em>5</em> 10 16 15 <em>9</em> 19
|
||||
21 <em>9</em> 14 16 <em>7</em> 19 8 <em>7</em> 25 23 18 8 23 26 20
|
||||
6 10 3 18 <em>5</em> 20 <em>11</em> 10 24 <em>4</em> 22 <em>11</em> 13 6 <em>5</em>
|
||||
1 12 20 15 19 14 21 16 12 6 2 0 12 3 <em>7</em>
|
||||
</code></pre>
|
||||
<p>After the next six numbers are drawn (<code>17</code>, <code>23</code>, <code>2</code>, <code>0</code>, <code>14</code>, and <code>21</code>), there are still no winners:</p>
|
||||
<pre><code>22 13 <em>17</em> <em>11</em> <em>0</em> 3 15 <em>0</em> <em>2</em> 22 <em>14</em> <em>21</em> <em>17</em> 24 <em>4</em>
|
||||
8 <em>2</em> <em>23</em> <em>4</em> 24 <em>9</em> 18 13 <em>17</em> <em>5</em> 10 16 15 <em>9</em> 19
|
||||
<em>21</em> <em>9</em> <em>14</em> 16 <em>7</em> 19 8 <em>7</em> 25 <em>23</em> 18 8 <em>23</em> 26 20
|
||||
6 10 3 18 <em>5</em> 20 <em>11</em> 10 24 <em>4</em> 22 <em>11</em> 13 6 <em>5</em>
|
||||
1 12 20 15 19 <em>14</em> <em>21</em> 16 12 6 <em>2</em> <em>0</em> 12 3 <em>7</em>
|
||||
</code></pre>
|
||||
<p>Finally, <code>24</code> is drawn:</p>
|
||||
<pre><code>22 13 <em>17</em> <em>11</em> <em>0</em> 3 15 <em>0</em> <em>2</em> 22 <em>14</em> <em>21</em> <em>17</em> <em>24</em> <em>4</em>
|
||||
8 <em>2</em> <em>23</em> <em>4</em> <em>24</em> <em>9</em> 18 13 <em>17</em> <em>5</em> 10 16 15 <em>9</em> 19
|
||||
<em>21</em> <em>9</em> <em>14</em> 16 <em>7</em> 19 8 <em>7</em> 25 <em>23</em> 18 8 <em>23</em> 26 20
|
||||
6 10 3 18 <em>5</em> 20 <em>11</em> 10 <em>24</em> <em>4</em> 22 <em>11</em> 13 6 <em>5</em>
|
||||
1 12 20 15 19 <em>14</em> <em>21</em> 16 12 6 <em>2</em> <em>0</em> 12 3 <em>7</em>
|
||||
</code></pre>
|
||||
<p>At this point, the third board <em>wins</em> because it has at least one complete row or column of marked numbers (in this case, the entire top row is marked: <code><em>14 21 17 24 4</em></code>).</p>
|
||||
<p>The <em>score</em> of the winning board can now be calculated. Start by finding the <em>sum of all unmarked numbers</em> on that board; in this case, the sum is <code>188</code>. Then, multiply that sum by <em>the number that was just called</em> when the board won, <code>24</code>, to get the final score, <code>188 * 24 = <em>4512</em></code>.</p>
|
||||
<p>To guarantee victory against the giant squid, figure out which board will win first. <em>What will your final score be if you choose that board?</em></p>
|
||||
</article><p>Your puzzle answer was <code>60368</code>.</p><article><h2 id="part2">--- Part Two ---</h2><p>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>.</p>
|
||||
<p>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 <em>figure out which board will win last</em> and choose that one. That way, no matter which boards it picks, it will win for sure.</p>
|
||||
<p>In the above example, the second board is the last to win, which happens after <code>13</code> 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 <code>148</code> for a final score of <code>148 * 13 = <em>1924</em></code>.</p>
|
||||
<p>Figure out which board will win last. <em>Once it wins, what would its final score be?</em></p>
|
||||
</article><p>Your puzzle answer was <code>17435</code>.</p></div>
|
73
05/problem.html
Normal file
73
05/problem.html
Normal file
|
@ -0,0 +1,73 @@
|
|||
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, text/html, charset=UTF-8" http-equiv="Content-Type">
|
||||
</meta>
|
||||
<title>Day 5 - Advent of Code 2021</title>
|
||||
<style type="text/css">
|
||||
body {
|
||||
margin: 30px auto;
|
||||
max-width: 650px;
|
||||
line-height: 1.4;
|
||||
padding: 0 10px;
|
||||
}
|
||||
h1, h2, h3 {
|
||||
line-height: 1.2;
|
||||
}
|
||||
</style>
|
||||
</head><div id="readability-page-1" class="page"><article><h2>--- Day 5: Hydrothermal Venture ---</h2><p>You come across a field of <a href="https://en.wikipedia.org/wiki/Hydrothermal_vent" target="_blank">hydrothermal vents</a> on the ocean floor! These vents constantly produce large, opaque clouds, so it would be best to avoid them if possible.</p>
|
||||
<p>They tend to form in <em>lines</em>; the submarine helpfully produces a list of nearby <span title="Maybe they're Bresenham vents.">lines of vents</span> (your puzzle input) for you to review. For example:</p>
|
||||
<pre><code>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
|
||||
</code></pre>
|
||||
<p>Each line of vents is given as a line segment in the format <code>x1,y1 -> x2,y2</code> where <code>x1</code>,<code>y1</code> are the coordinates of one end the line segment and <code>x2</code>,<code>y2</code> are the coordinates of the other end. These line segments include the points at both ends. In other words:</p>
|
||||
<ul>
|
||||
<li>An entry like <code>1,1 -> 1,3</code> covers points <code>1,1</code>, <code>1,2</code>, and <code>1,3</code>.</li>
|
||||
<li>An entry like <code>9,7 -> 7,7</code> covers points <code>9,7</code>, <code>8,7</code>, and <code>7,7</code>.</li>
|
||||
</ul>
|
||||
<p>For now, <em>only consider horizontal and vertical lines</em>: lines where either <code>x1 = x2</code> or <code>y1 = y2</code>.</p>
|
||||
<p>So, the horizontal and vertical lines from the above list would produce the following diagram:</p>
|
||||
<pre><code>.......1..
|
||||
..1....1..
|
||||
..1....1..
|
||||
.......1..
|
||||
.112111211
|
||||
..........
|
||||
..........
|
||||
..........
|
||||
..........
|
||||
222111....
|
||||
</code></pre>
|
||||
<p>In this diagram, the top left corner is <code>0,0</code> and the bottom right corner is <code>9,9</code>. Each position is shown as <em>the number of lines which cover that point</em> or <code>.</code> if no line covers that point. The top-left pair of <code>1</code>s, for example, comes from <code>2,2 -> 2,1</code>; the very bottom row is formed by the overlapping lines <code>0,9 -> 5,9</code> and <code>0,9 -> 2,9</code>.</p>
|
||||
<p>To avoid the most dangerous areas, you need to determine <em>the number of points where at least two lines overlap</em>. In the above example, this is anywhere in the diagram with a <code>2</code> or larger - a total of <code><em>5</em></code> points.</p>
|
||||
<p>Consider only horizontal and vertical lines. <em>At how many points do at least two lines overlap?</em></p>
|
||||
</article><p>Your puzzle answer was <code>5774</code>.</p><article><h2 id="part2">--- Part Two ---</h2><p>Unfortunately, considering only horizontal and vertical lines doesn't give you the full picture; you need to also consider <em>diagonal lines</em>.</p>
|
||||
<p>Because of the limits of the hydrothermal vent mapping system, the lines in your list will only ever be horizontal, vertical, or a diagonal line at exactly 45 degrees. In other words:</p>
|
||||
<ul>
|
||||
<li>An entry like <code>1,1 -> 3,3</code> covers points <code>1,1</code>, <code>2,2</code>, and <code>3,3</code>.</li>
|
||||
<li>An entry like <code>9,7 -> 7,9</code> covers points <code>9,7</code>, <code>8,8</code>, and <code>7,9</code>.</li>
|
||||
</ul>
|
||||
<p>Considering all lines from the above example would now produce the following diagram:</p>
|
||||
<pre><code>1.1....11.
|
||||
.111...2..
|
||||
..2.1.111.
|
||||
...1.2.2..
|
||||
.112313211
|
||||
...1.2....
|
||||
..1...1...
|
||||
.1.....1..
|
||||
1.......1.
|
||||
222111....
|
||||
</code></pre>
|
||||
<p>You still need to determine <em>the number of points where at least two lines overlap</em>. In the above example, this is still anywhere in the diagram with a <code>2</code> or larger - now a total of <code><em>12</em></code> points.</p>
|
||||
<p>Consider all of the lines. <em>At how many points do at least two lines overlap?</em></p>
|
||||
</article><p>Your puzzle answer was <code>18423</code>.</p></div>
|
62
06/problem.html
Normal file
62
06/problem.html
Normal file
|
@ -0,0 +1,62 @@
|
|||
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, text/html, charset=UTF-8" http-equiv="Content-Type">
|
||||
</meta>
|
||||
<title>Day 6 - Advent of Code 2021</title>
|
||||
<style type="text/css">
|
||||
body {
|
||||
margin: 30px auto;
|
||||
max-width: 650px;
|
||||
line-height: 1.4;
|
||||
padding: 0 10px;
|
||||
}
|
||||
h1, h2, h3 {
|
||||
line-height: 1.2;
|
||||
}
|
||||
</style>
|
||||
</head><div id="readability-page-1" class="page"><article><h2>--- Day 6: Lanternfish ---</h2><p>The sea floor is getting steeper. Maybe the sleigh keys got carried this way?</p>
|
||||
<p>A massive school of glowing <a href="https://en.wikipedia.org/wiki/Lanternfish" target="_blank">lanternfish</a> swims past. They must spawn quickly to reach such large numbers - maybe <em>exponentially</em> quickly? You should model their growth rate to be sure.</p>
|
||||
<p>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 <em>7</em> days.</p>
|
||||
<p>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 <em>the number of days until it creates a new lanternfish</em>.</p>
|
||||
<p>Furthermore, you reason, a <em>new</em> lanternfish would surely need slightly longer before it's capable of producing more lanternfish: two more days for its first cycle.</p>
|
||||
<p>So, suppose you have a lanternfish with an internal timer value of <code>3</code>:</p>
|
||||
<ul>
|
||||
<li>After one day, its internal timer would become <code>2</code>.</li>
|
||||
<li>After another day, its internal timer would become <code>1</code>.</li>
|
||||
<li>After another day, its internal timer would become <code>0</code>.</li>
|
||||
<li>After another day, its internal timer would reset to <code>6</code>, and it would create a <em>new</em> lanternfish with an internal timer of <code>8</code>.</li>
|
||||
<li>After another day, the first lanternfish would have an internal timer of <code>5</code>, and the second lanternfish would have an internal timer of <code>7</code>.</li>
|
||||
</ul>
|
||||
<p>A lanternfish that creates a new fish resets its timer to <code>6</code>, <em>not <code>7</code></em> (because <code>0</code> is included as a valid timer value). The new lanternfish starts with an internal timer of <code>8</code> and does not start counting down until the next day.</p>
|
||||
<p>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:</p>
|
||||
<pre><code>3,4,3,1,2</code></pre>
|
||||
<p>This list means that the first fish has an internal timer of <code>3</code>, the second fish has an internal timer of <code>4</code>, and so on until the fifth fish, which has an internal timer of <code>2</code>. Simulating these fish over several days would proceed as follows:</p>
|
||||
<pre><code>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
|
||||
</code></pre>
|
||||
<p>Each day, a <code>0</code> becomes a <code>6</code> and adds a new <code>8</code> to the end of the list, while each other number decreases by 1 if it was present at the start of the day.</p>
|
||||
<p>In this example, after 18 days, there are a total of <code>26</code> fish. After 80 days, there would be a total of <code><em>5934</em></code>.</p>
|
||||
<p>Find a way to simulate lanternfish. <em>How many lanternfish would there be after 80 days?</em></p>
|
||||
</article><p>Your puzzle answer was <code>396210</code>.</p><article><h2 id="part2">--- Part Two ---</h2><p>Suppose the lanternfish live forever and have unlimited food and space. Would they take over the entire ocean?</p>
|
||||
<p>After 256 days in the example above, there would be a total of <code><em>26984457539</em></code> lanternfish!</p>
|
||||
<p><em>How many lanternfish would there be after 256 days?</em></p>
|
||||
</article><p>Your puzzle answer was <code>1770823541496</code>.</p></div>
|
67
07/problem.html
Normal file
67
07/problem.html
Normal file
|
@ -0,0 +1,67 @@
|
|||
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, text/html, charset=UTF-8" http-equiv="Content-Type">
|
||||
</meta>
|
||||
<title>Day 7 - Advent of Code 2021</title>
|
||||
<style type="text/css">
|
||||
body {
|
||||
margin: 30px auto;
|
||||
max-width: 650px;
|
||||
line-height: 1.4;
|
||||
padding: 0 10px;
|
||||
}
|
||||
h1, h2, h3 {
|
||||
line-height: 1.2;
|
||||
}
|
||||
</style>
|
||||
</head><div id="readability-page-1" class="page"><div>
|
||||
|
||||
<article><h2>--- Day 7: The Treachery of Whales ---</h2><p>A giant <a href="https://en.wikipedia.org/wiki/Sperm_whale" target="_blank">whale</a> has decided your submarine is its next meal, and it's much faster than you are. There's nowhere to run!</p>
|
||||
<p>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 <em>massive underground cave system</em> just beyond where they're aiming!</p>
|
||||
<p>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?</p>
|
||||
<p>There's one major catch - crab submarines can only move horizontally.</p>
|
||||
<p>You quickly make a list of <em>the horizontal position of each crab</em> (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.</p>
|
||||
<p>For example, consider the following horizontal positions:</p>
|
||||
<pre><code>16,1,2,0,4,2,7,1,2,14</code></pre>
|
||||
<p>This means there's a crab with horizontal position <code>16</code>, a crab with horizontal position <code>1</code>, and so on.</p>
|
||||
<p>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 <code>2</code>:</p>
|
||||
<ul>
|
||||
<li>Move from <code>16</code> to <code>2</code>: <code>14</code> fuel</li>
|
||||
<li>Move from <code>1</code> to <code>2</code>: <code>1</code> fuel</li>
|
||||
<li>Move from <code>2</code> to <code>2</code>: <code>0</code> fuel</li>
|
||||
<li>Move from <code>0</code> to <code>2</code>: <code>2</code> fuel</li>
|
||||
<li>Move from <code>4</code> to <code>2</code>: <code>2</code> fuel</li>
|
||||
<li>Move from <code>2</code> to <code>2</code>: <code>0</code> fuel</li>
|
||||
<li>Move from <code>7</code> to <code>2</code>: <code>5</code> fuel</li>
|
||||
<li>Move from <code>1</code> to <code>2</code>: <code>1</code> fuel</li>
|
||||
<li>Move from <code>2</code> to <code>2</code>: <code>0</code> fuel</li>
|
||||
<li>Move from <code>14</code> to <code>2</code>: <code>12</code> fuel</li>
|
||||
</ul>
|
||||
<p>This costs a total of <code><em>37</em></code> fuel. This is the cheapest possible outcome; more expensive outcomes include aligning at position <code>1</code> (<code>41</code> fuel), position <code>3</code> (<code>39</code> fuel), or position <code>10</code> (<code>71</code> fuel).</p>
|
||||
<p>Determine the horizontal position that the crabs can align to using the least fuel possible. <em>How much fuel must they spend to align to that position?</em></p>
|
||||
</article>
|
||||
<p>Your puzzle answer was <code>339321</code>.</p><article><h2 id="part2">--- Part Two ---</h2><p>The crabs don't seem interested in your proposed solution. Perhaps you misunderstand crab engineering?</p>
|
||||
<p>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 <code>1</code>, the second step costs <code>2</code>, the third step costs <code>3</code>, and so on.</p>
|
||||
<p>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 <code>5</code>:</p>
|
||||
<ul>
|
||||
<li>Move from <code>16</code> to <code>5</code>: <code>66</code> fuel</li>
|
||||
<li>Move from <code>1</code> to <code>5</code>: <code>10</code> fuel</li>
|
||||
<li>Move from <code>2</code> to <code>5</code>: <code>6</code> fuel</li>
|
||||
<li>Move from <code>0</code> to <code>5</code>: <code>15</code> fuel</li>
|
||||
<li>Move from <code>4</code> to <code>5</code>: <code>1</code> fuel</li>
|
||||
<li>Move from <code>2</code> to <code>5</code>: <code>6</code> fuel</li>
|
||||
<li>Move from <code>7</code> to <code>5</code>: <code>3</code> fuel</li>
|
||||
<li>Move from <code>1</code> to <code>5</code>: <code>10</code> fuel</li>
|
||||
<li>Move from <code>2</code> to <code>5</code>: <code>6</code> fuel</li>
|
||||
<li>Move from <code>14</code> to <code>5</code>: <code>45</code> fuel</li>
|
||||
</ul>
|
||||
<p>This costs a total of <code><em>168</em></code> fuel. This is the new cheapest possible outcome; the old alignment position (<code>2</code>) now costs <code>206</code> fuel instead.</p>
|
||||
<p>Determine the horizontal position that the crabs can align to using the least fuel possible so they can make you an escape route! <em>How much fuel must they spend to align to that position?</em></p>
|
||||
</article>
|
||||
<p>Your puzzle answer was <code>95476244</code>.</p><p>Both parts of this puzzle are complete! They provide two gold stars: **</p>
|
||||
<p>At this point, you should <a href="https://adventofcode.com/2021">return to your Advent calendar</a> and try another puzzle.</p>
|
||||
<p>If you still want to see it, you can <a href="https://adventofcode.com/2021/day/7/input" target="_blank">get your puzzle input</a>.</p>
|
||||
<p>You can also this puzzle.</p>
|
||||
</div></div>
|
122
08/problem.html
Normal file
122
08/problem.html
Normal file
|
@ -0,0 +1,122 @@
|
|||
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, text/html, charset=UTF-8" http-equiv="Content-Type">
|
||||
</meta>
|
||||
<title>Day 8 - Advent of Code 2021</title>
|
||||
<style type="text/css">
|
||||
body {
|
||||
margin: 30px auto;
|
||||
max-width: 650px;
|
||||
line-height: 1.4;
|
||||
padding: 0 10px;
|
||||
}
|
||||
h1, h2, h3 {
|
||||
line-height: 1.2;
|
||||
}
|
||||
</style>
|
||||
</head><div id="readability-page-1" class="page"><article><h2>--- Day 8: Seven Segment Search ---</h2><p>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.</p>
|
||||
<p>As your submarine slowly makes its way through the cave system, you notice that the four-digit <a href="https://en.wikipedia.org/wiki/Seven-segment_display" target="_blank">seven-segment displays</a> 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.</p>
|
||||
<p>Each digit of a seven-segment display is rendered by turning on or off any of seven segments named <code>a</code> through <code>g</code>:</p>
|
||||
<pre><code> 0: 1: 2: 3: 4:
|
||||
<em>aaaa</em> .... <em>aaaa aaaa</em> ....
|
||||
<em>b c</em> . <em>c</em> . <em>c</em> . <em>c b c</em>
|
||||
<em>b c</em> . <em>c</em> . <em>c</em> . <em>c b c</em>
|
||||
.... .... <em>dddd dddd dddd</em>
|
||||
<em>e f</em> . <em>f e</em> . . <em>f</em> . <em>f</em>
|
||||
<em>e f</em> . <em>f e</em> . . <em>f</em> . <em>f</em>
|
||||
<em>gggg</em> .... <em>gggg gggg</em> ....
|
||||
|
||||
5: 6: 7: 8: 9:
|
||||
<em>aaaa aaaa aaaa aaaa aaaa</em>
|
||||
<em>b</em> . <em>b</em> . . <em>c b c b c</em>
|
||||
<em>b</em> . <em>b</em> . . <em>c b c b c</em>
|
||||
<em>dddd dddd</em> .... <em>dddd dddd</em>
|
||||
. <em>f e f</em> . <em>f e f</em> . <em>f</em>
|
||||
. <em>f e f</em> . <em>f e f</em> . <em>f</em>
|
||||
<em>gggg gggg</em> .... <em>gggg gggg</em>
|
||||
</code></pre>
|
||||
<p>So, to render a <code>1</code>, only segments <code>c</code> and <code>f</code> would be turned on; the rest would be off. To render a <code>7</code>, only segments <code>a</code>, <code>c</code>, and <code>f</code> would be turned on.</p>
|
||||
<p>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 <code>a</code> through <code>g</code>, but those wires are connected to segments <em>randomly</em>. Worse, the wire/segment connections are mixed up separately for each four-digit display! (All of the digits <em>within</em> a display use the same connections, though.)</p>
|
||||
<p>So, you might know that only signal wires <code>b</code> and <code>g</code> are turned on, but that doesn't mean <em>segments</em> <code>b</code> and <code>g</code> are turned on: the only digit that uses two segments is <code>1</code>, so it must mean segments <code>c</code> and <code>f</code> are meant to be on. With just that information, you still can't tell which wire (<code>b</code>/<code>g</code>) goes to which segment (<code>c</code>/<code>f</code>). For that, you'll need to collect more information.</p>
|
||||
<p>For each display, you watch the changing signals for a while, make a note of <em>all ten unique signal patterns</em> you see, and then write down a single <em>four digit output value</em> (your puzzle input). Using the signal patterns, you should be able to work out which pattern corresponds to which digit.</p>
|
||||
<p>For example, here is what you might see in a single entry in your notes:</p>
|
||||
<pre><code>acedgfb cdfbe gcdfa fbcad dab cefabd cdfgeb eafb cagedb ab |
|
||||
cdfeb fcadb cdfeb cdbaf</code></pre>
|
||||
<p>(The entry is wrapped here to two lines so it fits; in your notes, it will all be on a single line.)</p>
|
||||
<p>Each entry consists of ten <em>unique signal patterns</em>, a <code>|</code> delimiter, and finally the <em>four digit output value</em>. 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 <code>7</code> is the only digit that uses three segments, <code>dab</code> in the above example means that to render a <code>7</code>, signal lines <code>d</code>, <code>a</code>, and <code>b</code> are on. Because <code>4</code> is the only digit that uses four segments, <code>eafb</code> means that to render a <code>4</code>, signal lines <code>e</code>, <code>a</code>, <code>f</code>, and <code>b</code> are on.</p>
|
||||
<p>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 (<code>cdfeb fcadb cdfeb cdbaf</code>) use five segments and are more difficult to deduce.</p>
|
||||
<p>For now, <em>focus on the easy digits</em>. Consider this larger example:</p>
|
||||
<pre><code>be cfbegad cbdgef fgaecd cgeb fdcge agebfd fecdb fabcd edb |
|
||||
<em>fdgacbe</em> cefdb cefbgd <em>gcbe</em>
|
||||
edbfga begcd cbg gc gcadebf fbgde acbgfd abcde gfcbed gfec |
|
||||
fcgedb <em>cgb</em> <em>dgebacf</em> <em>gc</em>
|
||||
fgaebd cg bdaec gdafb agbcfd gdcbef bgcad gfac gcb cdgabef |
|
||||
<em>cg</em> <em>cg</em> fdcagb <em>cbg</em>
|
||||
fbegcd cbd adcefb dageb afcb bc aefdc ecdab fgdeca fcdbega |
|
||||
efabcd cedba gadfec <em>cb</em>
|
||||
aecbfdg fbg gf bafeg dbefa fcge gcbea fcaegb dgceab fcbdga |
|
||||
<em>gecf</em> <em>egdcabf</em> <em>bgf</em> bfgea
|
||||
fgeab ca afcebg bdacfeg cfaedg gcfdb baec bfadeg bafgc acf |
|
||||
<em>gebdcfa</em> <em>ecba</em> <em>ca</em> <em>fadegcb</em>
|
||||
dbcfg fgd bdegcaf fgec aegbdf ecdfab fbedc dacgb gdcebf gf |
|
||||
<em>cefg</em> dcbef <em>fcge</em> <em>gbcadfe</em>
|
||||
bdfegc cbegaf gecbf dfcage bdacg ed bedf ced adcbefg gebcd |
|
||||
<em>ed</em> bcgafe cdgba cbgef
|
||||
egadfb cdbfeg cegd fecab cgb gbdefca cg fgcdab egfdb bfceg |
|
||||
<em>gbdfcae</em> <em>bgc</em> <em>cg</em> <em>cgb</em>
|
||||
gcafb gcf dcaebfg ecagb gf abcdeg gaef cafbge fdbac fegbdc |
|
||||
<em>fgae</em> cfgab <em>fg</em> bagce
|
||||
</code></pre>
|
||||
<p>Because the digits <code>1</code>, <code>4</code>, <code>7</code>, and <code>8</code> each use a unique number of segments, you should be able to tell which combinations of signals correspond to those digits. Counting <em>only digits in the output values</em> (the part after <code>|</code> on each line), in the above example, there are <code><em>26</em></code> instances of digits that use a unique number of segments (highlighted above).</p>
|
||||
<p><em>In the output values, how many times do digits <code>1</code>, <code>4</code>, <code>7</code>, or <code>8</code> appear?</em></p>
|
||||
</article><p>Your puzzle answer was <code>349</code>.</p><article><h2 id="part2">--- Part Two ---</h2><p>Through a little deduction, you should now be able to determine the remaining digits. Consider again the first example above:</p>
|
||||
<pre><code>acedgfb cdfbe gcdfa fbcad dab cefabd cdfgeb eafb cagedb ab |
|
||||
cdfeb fcadb cdfeb cdbaf</code></pre>
|
||||
<p>After some careful analysis, the mapping between signal wires and segments only make sense in the following configuration:</p>
|
||||
<pre><code> dddd
|
||||
e a
|
||||
e a
|
||||
ffff
|
||||
g b
|
||||
g b
|
||||
cccc
|
||||
</code></pre>
|
||||
<p>So, the unique signal patterns would correspond to the following digits:</p>
|
||||
<ul>
|
||||
<li><code>acedgfb</code>: <code>8</code></li>
|
||||
<li><code>cdfbe</code>: <code>5</code></li>
|
||||
<li><code>gcdfa</code>: <code>2</code></li>
|
||||
<li><code>fbcad</code>: <code>3</code></li>
|
||||
<li><code>dab</code>: <code>7</code></li>
|
||||
<li><code>cefabd</code>: <code>9</code></li>
|
||||
<li><code>cdfgeb</code>: <code>6</code></li>
|
||||
<li><code>eafb</code>: <code>4</code></li>
|
||||
<li><code>cagedb</code>: <code>0</code></li>
|
||||
<li><code>ab</code>: <code>1</code></li>
|
||||
</ul>
|
||||
<p>Then, the four digits of the output value can be decoded:</p>
|
||||
<ul>
|
||||
<li><code>cdfeb</code>: <code><em>5</em></code></li>
|
||||
<li><code>fcadb</code>: <code><em>3</em></code></li>
|
||||
<li><code>cdfeb</code>: <code><em>5</em></code></li>
|
||||
<li><code>cdbaf</code>: <code><em>3</em></code></li>
|
||||
</ul>
|
||||
<p>Therefore, the output value for this entry is <code><em>5353</em></code>.</p>
|
||||
<p>Following this same process for each entry in the second, larger example above, the output value of each entry can be determined:</p>
|
||||
<ul>
|
||||
<li><code>fdgacbe cefdb cefbgd gcbe</code>: <code>8394</code></li>
|
||||
<li><code>fcgedb cgb dgebacf gc</code>: <code>9781</code></li>
|
||||
<li><code>cg cg fdcagb cbg</code>: <code>1197</code></li>
|
||||
<li><code>efabcd cedba gadfec cb</code>: <code>9361</code></li>
|
||||
<li><code>gecf egdcabf bgf bfgea</code>: <code>4873</code></li>
|
||||
<li><code>gebdcfa ecba ca fadegcb</code>: <code>8418</code></li>
|
||||
<li><code>cefg dcbef fcge gbcadfe</code>: <code>4548</code></li>
|
||||
<li><code>ed bcgafe cdgba cbgef</code>: <code>1625</code></li>
|
||||
<li><code>gbdfcae bgc cg cgb</code>: <code>8717</code></li>
|
||||
<li><code>fgae cfgab fg bagce</code>: <code>4315</code></li>
|
||||
</ul>
|
||||
<p>Adding all of the output values in this larger example produces <code><em>61229</em></code>.</p>
|
||||
<p>For each entry, determine all of the wire/segment connections and decode the four-digit output values. <em>What do you get if you add up all of the output values?</em></p>
|
||||
</article><p>Your puzzle answer was <code>1070957</code>.</p></div>
|
74
09/problem.html
Normal file
74
09/problem.html
Normal file
|
@ -0,0 +1,74 @@
|
|||
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, text/html, charset=UTF-8" http-equiv="Content-Type">
|
||||
</meta>
|
||||
<title>Day 9 - Advent of Code 2021</title>
|
||||
<style type="text/css">
|
||||
body {
|
||||
margin: 30px auto;
|
||||
max-width: 650px;
|
||||
line-height: 1.4;
|
||||
padding: 0 10px;
|
||||
}
|
||||
h1, h2, h3 {
|
||||
line-height: 1.2;
|
||||
}
|
||||
</style>
|
||||
</head><div id="readability-page-1" class="page"><div>
|
||||
|
||||
<article><h2>--- Day 9: Smoke Basin ---</h2><p>These caves seem to be <a href="https://en.wikipedia.org/wiki/Lava_tube" target="_blank">lava tubes</a>. 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>.</p>
|
||||
<p>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).</p>
|
||||
<p>Smoke flows to the lowest point of the area it's in. For example, consider the following heightmap:</p>
|
||||
<pre><code>2<em>1</em>9994321<em>0</em>
|
||||
3987894921
|
||||
98<em>5</em>6789892
|
||||
8767896789
|
||||
989996<em>5</em>678
|
||||
</code></pre>
|
||||
<p>Each number corresponds to the height of a particular location, where <code>9</code> is the highest and <code>0</code> is the lowest a location can be.</p>
|
||||
<p>Your first goal is to find the <em>low points</em> - 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.)</p>
|
||||
<p>In the above example, there are <em>four</em> low points, all highlighted: two are in the first row (a <code>1</code> and a <code>0</code>), one is in the third row (a <code>5</code>), and one is in the bottom row (also a <code>5</code>). All other locations on the heightmap have some lower adjacent location, and so are not low points.</p>
|
||||
<p>The <em>risk level</em> of a low point is <em>1 plus its height</em>. In the above example, the risk levels of the low points are <code>2</code>, <code>1</code>, <code>6</code>, and <code>6</code>. The sum of the risk levels of all low points in the heightmap is therefore <code><em>15</em></code>.</p>
|
||||
<p>Find all of the low points on your heightmap. <em>What is the sum of the risk levels of all low points on your heightmap?</em></p>
|
||||
</article>
|
||||
<p>Your puzzle answer was <code>498</code>.</p><article><h2 id="part2">--- Part Two ---</h2><p>Next, you need to find the largest basins so you know what areas are most important to avoid.</p>
|
||||
<p>A <em>basin</em> 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 <code>9</code> do not count as being in any basin, and all other locations will always be part of exactly one basin.</p>
|
||||
<p>The <em>size</em> of a basin is the number of locations within the basin, including the low point. The example above has four basins.</p>
|
||||
<p>The top-left basin, size <code>3</code>:</p>
|
||||
<pre><code><em>21</em>99943210
|
||||
<em>3</em>987894921
|
||||
9856789892
|
||||
8767896789
|
||||
9899965678
|
||||
</code></pre>
|
||||
<p>The top-right basin, size <code>9</code>:</p>
|
||||
<pre><code>21999<em>43210</em>
|
||||
398789<em>4</em>9<em>21</em>
|
||||
985678989<em>2</em>
|
||||
8767896789
|
||||
9899965678
|
||||
</code></pre>
|
||||
<p>The middle basin, size <code>14</code>:</p>
|
||||
<pre><code>2199943210
|
||||
39<em>878</em>94921
|
||||
9<em>85678</em>9892
|
||||
<em>87678</em>96789
|
||||
9<em>8</em>99965678
|
||||
</code></pre>
|
||||
<p>The bottom-right basin, size <code>9</code>:</p>
|
||||
<pre><code>2199943210
|
||||
3987894921
|
||||
9856789<em>8</em>92
|
||||
876789<em>678</em>9
|
||||
98999<em>65678</em>
|
||||
</code></pre>
|
||||
<p>Find the three largest basins and multiply their sizes together. In the above example, this is <code>9 * 14 * 9 = <em>1134</em></code>.</p>
|
||||
<p><em>What do you get if you multiply together the sizes of the three largest basins?</em></p>
|
||||
</article>
|
||||
<p>Your puzzle answer was <code>1071000</code>.</p><p>Both parts of this puzzle are complete! They provide two gold stars: **</p>
|
||||
<p>At this point, you should <a href="https://adventofcode.com/2021">return to your Advent calendar</a> and try another puzzle.</p>
|
||||
<p>If you still want to see it, you can <a href="https://adventofcode.com/2021/day/9/input" target="_blank">get your puzzle input</a>.</p>
|
||||
<p>You can also this puzzle.</p>
|
||||
</div></div>
|
99
10/problem.html
Normal file
99
10/problem.html
Normal file
|
@ -0,0 +1,99 @@
|
|||
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, text/html, charset=UTF-8" http-equiv="Content-Type">
|
||||
</meta>
|
||||
<title>Day 10 - Advent of Code 2021</title>
|
||||
<style type="text/css">
|
||||
body {
|
||||
margin: 30px auto;
|
||||
max-width: 650px;
|
||||
line-height: 1.4;
|
||||
padding: 0 10px;
|
||||
}
|
||||
h1, h2, h3 {
|
||||
line-height: 1.2;
|
||||
}
|
||||
</style>
|
||||
</head><div id="readability-page-1" class="page"><article><h2>--- Day 10: Syntax Scoring ---</h2><p>You ask the submarine to determine the best route out of the deep-sea cave, but it only replies:</p>
|
||||
<pre><code>Syntax error in navigation subsystem on line: <span title="Some days, that's just how it is.">all of them</span></code></pre>
|
||||
<p><em>All of them?!</em> The damage is worse than you thought. You bring up a copy of the navigation subsystem (your puzzle input).</p>
|
||||
<p>The navigation subsystem syntax is made of several lines containing <em>chunks</em>. There are one or more chunks on each line, and chunks contain zero or more other chunks. Adjacent chunks are not separated by any delimiter; if one chunk stops, the next chunk (if any) can immediately start. Every chunk must <em>open</em> and <em>close</em> with one of four legal pairs of matching characters:</p>
|
||||
<ul>
|
||||
<li>If a chunk opens with <code>(</code>, it must close with <code>)</code>.</li>
|
||||
<li>If a chunk opens with <code>[</code>, it must close with <code>]</code>.</li>
|
||||
<li>If a chunk opens with <code>{</code>, it must close with <code>}</code>.</li>
|
||||
<li>If a chunk opens with <code><</code>, it must close with <code>></code>.</li>
|
||||
</ul>
|
||||
<p>So, <code>()</code> is a legal chunk that contains no other chunks, as is <code>[]</code>. More complex but valid chunks include <code>([])</code>, <code>{()()()}</code>, <code><([{}])></code>, <code>[<>({}){}[([])<>]]</code>, and even <code>(((((((((())))))))))</code>.</p>
|
||||
<p>Some lines are <em>incomplete</em>, but others are <em>corrupted</em>. Find and discard the corrupted lines first.</p>
|
||||
<p>A corrupted line is one where a chunk <em>closes with the wrong character</em> - that is, where the characters it opens and closes with do not form one of the four legal pairs listed above.</p>
|
||||
<p>Examples of corrupted chunks include <code>(]</code>, <code>{()()()></code>, <code>(((()))}</code>, and <code><([]){()}[{}])</code>. Such a chunk can appear anywhere within a line, and its presence causes the whole line to be considered corrupted.</p>
|
||||
<p>For example, consider the following navigation subsystem:</p>
|
||||
<pre><code>[({(<(())[]>[[{[]{<()<>>
|
||||
[(()[<>])]({[<{<<[]>>(
|
||||
{([(<{}[<>[]}>{[]{[(<()>
|
||||
(((({<>}<{<{<>}{[]{[]{}
|
||||
[[<[([]))<([[{}[[()]]]
|
||||
[{[{({}]{}}([{[{{{}}([]
|
||||
{<[[]]>}<{[{[{[]{()[[[]
|
||||
[<(<(<(<{}))><([]([]()
|
||||
<{([([[(<>()){}]>(<<{{
|
||||
<{([{{}}[<[[[<>{}]]]>[]]
|
||||
</code></pre>
|
||||
<p>Some of the lines aren't corrupted, just incomplete; you can ignore these lines for now. The remaining five lines are corrupted:</p>
|
||||
<ul>
|
||||
<li><code>{([(<{}[<>[]}>{[]{[(<()></code> - Expected <code>]</code>, but found <code>}</code> instead.</li>
|
||||
<li><code>[[<[([]))<([[{}[[()]]]</code> - Expected <code>]</code>, but found <code>)</code> instead.</li>
|
||||
<li><code>[{[{({}]{}}([{[{{{}}([]</code> - Expected <code>)</code>, but found <code>]</code> instead.</li>
|
||||
<li><code>[<(<(<(<{}))><([]([]()</code> - Expected <code>></code>, but found <code>)</code> instead.</li>
|
||||
<li><code><{([([[(<>()){}]>(<<{{</code> - Expected <code>]</code>, but found <code>></code> instead.</li>
|
||||
</ul>
|
||||
<p>Stop at the first incorrect closing character on each corrupted line.</p>
|
||||
<p>Did you know that syntax checkers actually have contests to see who can get the high score for syntax errors in a file? It's true! To calculate the syntax error score for a line, take the <em>first illegal character</em> on the line and look it up in the following table:</p>
|
||||
<ul>
|
||||
<li><code>)</code>: <code>3</code> points.</li>
|
||||
<li><code>]</code>: <code>57</code> points.</li>
|
||||
<li><code>}</code>: <code>1197</code> points.</li>
|
||||
<li><code>></code>: <code>25137</code> points.</li>
|
||||
</ul>
|
||||
<p>In the above example, an illegal <code>)</code> was found twice (<code>2*3 = <em>6</em></code> points), an illegal <code>]</code> was found once (<code><em>57</em></code> points), an illegal <code>}</code> was found once (<code><em>1197</em></code> points), and an illegal <code>></code> was found once (<code><em>25137</em></code> points). So, the total syntax error score for this file is <code>6+57+1197+25137 = <em>26397</em></code> points!</p>
|
||||
<p>Find the first illegal character in each corrupted line of the navigation subsystem. <em>What is the total syntax error score for those errors?</em></p>
|
||||
</article><p>Your puzzle answer was <code>319329</code>.</p><article><h2 id="part2">--- Part Two ---</h2><p>Now, discard the corrupted lines. The remaining lines are <em>incomplete</em>.</p>
|
||||
<p>Incomplete lines don't have any incorrect characters - instead, they're missing some closing characters at the end of the line. To repair the navigation subsystem, you just need to figure out <em>the sequence of closing characters</em> that complete all open chunks in the line.</p>
|
||||
<p>You can only use closing characters (<code>)</code>, <code>]</code>, <code>}</code>, or <code>></code>), and you must add them in the correct order so that only legal pairs are formed and all chunks end up closed.</p>
|
||||
<p>In the example above, there are five incomplete lines:</p>
|
||||
<ul>
|
||||
<li><code>[({(<(())[]>[[{[]{<()<>></code> - Complete by adding <code>}}]])})]</code>.</li>
|
||||
<li><code>[(()[<>])]({[<{<<[]>>(</code> - Complete by adding <code>)}>]})</code>.</li>
|
||||
<li><code>(((({<>}<{<{<>}{[]{[]{}</code> - Complete by adding <code>}}>}>))))</code>.</li>
|
||||
<li><code>{<[[]]>}<{[{[{[]{()[[[]</code> - Complete by adding <code>]]}}]}]}></code>.</li>
|
||||
<li><code><{([{{}}[<[[[<>{}]]]>[]]</code> - Complete by adding <code>])}></code>.</li>
|
||||
</ul>
|
||||
<p>Did you know that autocomplete tools <em>also</em> have contests? It's true! The score is determined by considering the completion string character-by-character. Start with a total score of <code>0</code>. Then, for each character, multiply the total score by 5 and then increase the total score by the point value given for the character in the following table:</p>
|
||||
<ul>
|
||||
<li><code>)</code>: <code>1</code> point.</li>
|
||||
<li><code>]</code>: <code>2</code> points.</li>
|
||||
<li><code>}</code>: <code>3</code> points.</li>
|
||||
<li><code>></code>: <code>4</code> points.</li>
|
||||
</ul>
|
||||
<p>So, the last completion string above - <code>])}></code> - would be scored as follows:</p>
|
||||
<ul>
|
||||
<li>Start with a total score of <code>0</code>.</li>
|
||||
<li>Multiply the total score by 5 to get <code>0</code>, then add the value of <code>]</code> (2) to get a new total score of <code>2</code>.</li>
|
||||
<li>Multiply the total score by 5 to get <code>10</code>, then add the value of <code>)</code> (1) to get a new total score of <code>11</code>.</li>
|
||||
<li>Multiply the total score by 5 to get <code>55</code>, then add the value of <code>}</code> (3) to get a new total score of <code>58</code>.</li>
|
||||
<li>Multiply the total score by 5 to get <code>290</code>, then add the value of <code>></code> (4) to get a new total score of <code>294</code>.</li>
|
||||
</ul>
|
||||
<p>The five lines' completion strings have total scores as follows:</p>
|
||||
<ul>
|
||||
<li><code>}}]])})]</code> - <code>288957</code> total points.</li>
|
||||
<li><code>)}>]})</code> - <code>5566</code> total points.</li>
|
||||
<li><code>}}>}>))))</code> - <code>1480781</code> total points.</li>
|
||||
<li><code>]]}}]}]}></code> - <code>995444</code> total points.</li>
|
||||
<li><code>])}></code> - <code>294</code> total points.</li>
|
||||
</ul>
|
||||
<p>Autocomplete tools are an odd bunch: the winner is found by <em>sorting</em> all of the scores and then taking the <em>middle</em> score. (There will always be an odd number of scores to consider.) In this example, the middle score is <code><em>288957</em></code> because there are the same number of scores smaller and larger than it.</p>
|
||||
<p>Find the completion string for each incomplete line, score the completion strings, and sort the scores. <em>What is the middle score?</em></p>
|
||||
</article><p>Your puzzle answer was <code>3515583998</code>.</p></div>
|
348
11/problem.html
Normal file
348
11/problem.html
Normal file
|
@ -0,0 +1,348 @@
|
|||
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, text/html, charset=UTF-8" http-equiv="Content-Type">
|
||||
</meta>
|
||||
<title>Day 11 - Advent of Code 2021</title>
|
||||
<style type="text/css">
|
||||
body {
|
||||
margin: 30px auto;
|
||||
max-width: 650px;
|
||||
line-height: 1.4;
|
||||
padding: 0 10px;
|
||||
}
|
||||
h1, h2, h3 {
|
||||
line-height: 1.2;
|
||||
}
|
||||
</style>
|
||||
</head><div id="readability-page-1" class="page"><article><h2>--- Day 11: Dumbo Octopus ---</h2><p>You enter a large cavern full of rare bioluminescent <a href="https://www.youtube.com/watch?v=eih-VSaS2g0" target="_blank">dumbo octopuses</a>! They seem to not like the Christmas lights on your submarine, so you turn them off for now.</p>
|
||||
<p>There are 100 <span title="I know it's weird; I grew up saying 'octopi' too.">octopuses</span> arranged neatly in a 10 by 10 grid. Each octopus slowly gains <em>energy</em> over time and <em>flashes</em> brightly for a moment when its energy is full. Although your lights are off, maybe you could navigate through the cave without disturbing the octopuses if you could predict when the flashes of light will happen.</p>
|
||||
<p>Each octopus has an <em>energy level</em> - your submarine can remotely measure the energy level of each octopus (your puzzle input). For example:</p>
|
||||
<pre><code>5483143223
|
||||
2745854711
|
||||
5264556173
|
||||
6141336146
|
||||
6357385478
|
||||
4167524645
|
||||
2176841721
|
||||
6882881134
|
||||
4846848554
|
||||
5283751526
|
||||
</code></pre>
|
||||
<p>The energy level of each octopus is a value between <code>0</code> and <code>9</code>. Here, the top-left octopus has an energy level of <code>5</code>, the bottom-right one has an energy level of <code>6</code>, and so on.</p>
|
||||
<p>You can model the energy levels and flashes of light in <em>steps</em>. During a single step, the following occurs:</p>
|
||||
<ul>
|
||||
<li>First, the energy level of each octopus increases by <code>1</code>.</li>
|
||||
<li>Then, any octopus with an energy level greater than <code>9</code> <em>flashes</em>. This increases the energy level of all adjacent octopuses by <code>1</code>, including octopuses that are diagonally adjacent. If this causes an octopus to have an energy level greater than <code>9</code>, it <em>also flashes</em>. This process continues as long as new octopuses keep having their energy level increased beyond <code>9</code>. (An octopus can only flash <em>at most once per step</em>.)</li>
|
||||
<li>Finally, any octopus that flashed during this step has its energy level set to <code>0</code>, as it used all of its energy to flash.</li>
|
||||
</ul>
|
||||
<p>Adjacent flashes can cause an octopus to flash on a step even if it begins that step with very little energy. Consider the middle octopus with <code>1</code> energy in this situation:</p>
|
||||
<pre><code>Before any steps:
|
||||
11111
|
||||
19991
|
||||
19191
|
||||
19991
|
||||
11111
|
||||
|
||||
After step 1:
|
||||
34543
|
||||
4<em>000</em>4
|
||||
5<em>000</em>5
|
||||
4<em>000</em>4
|
||||
34543
|
||||
|
||||
After step 2:
|
||||
45654
|
||||
51115
|
||||
61116
|
||||
51115
|
||||
45654
|
||||
</code></pre>
|
||||
<p>An octopus is <em>highlighted</em> when it flashed during the given step.</p>
|
||||
<p>Here is how the larger example above progresses:</p>
|
||||
<pre><code>Before any steps:
|
||||
5483143223
|
||||
2745854711
|
||||
5264556173
|
||||
6141336146
|
||||
6357385478
|
||||
4167524645
|
||||
2176841721
|
||||
6882881134
|
||||
4846848554
|
||||
5283751526
|
||||
|
||||
After step 1:
|
||||
6594254334
|
||||
3856965822
|
||||
6375667284
|
||||
7252447257
|
||||
7468496589
|
||||
5278635756
|
||||
3287952832
|
||||
7993992245
|
||||
5957959665
|
||||
6394862637
|
||||
|
||||
After step 2:
|
||||
88<em>0</em>7476555
|
||||
5<em>0</em>89<em>0</em>87<em>0</em>54
|
||||
85978896<em>0</em>8
|
||||
84857696<em>00</em>
|
||||
87<em>00</em>9<em>0</em>88<em>00</em>
|
||||
66<em>000</em>88989
|
||||
68<em>0000</em>5943
|
||||
<em>000000</em>7456
|
||||
9<em>000000</em>876
|
||||
87<em>0000</em>6848
|
||||
|
||||
After step 3:
|
||||
<em>00</em>5<em>0</em>9<em>00</em>866
|
||||
85<em>00</em>8<em>00</em>575
|
||||
99<em>000000</em>39
|
||||
97<em>000000</em>41
|
||||
9935<em>0</em>8<em>00</em>63
|
||||
77123<em>00000</em>
|
||||
791125<em>000</em>9
|
||||
221113<em>0000</em>
|
||||
<em>0</em>421125<em>000</em>
|
||||
<em>00</em>21119<em>000</em>
|
||||
|
||||
After step 4:
|
||||
2263<em>0</em>31977
|
||||
<em>0</em>923<em>0</em>31697
|
||||
<em>00</em>3222115<em>0</em>
|
||||
<em>00</em>41111163
|
||||
<em>00</em>76191174
|
||||
<em>00</em>53411122
|
||||
<em>00</em>4236112<em>0</em>
|
||||
5532241122
|
||||
1532247211
|
||||
113223<em>0</em>211
|
||||
|
||||
After step 5:
|
||||
4484144<em>000</em>
|
||||
2<em>0</em>44144<em>000</em>
|
||||
2253333493
|
||||
1152333274
|
||||
11873<em>0</em>3285
|
||||
1164633233
|
||||
1153472231
|
||||
6643352233
|
||||
2643358322
|
||||
2243341322
|
||||
|
||||
After step 6:
|
||||
5595255111
|
||||
3155255222
|
||||
33644446<em>0</em>5
|
||||
2263444496
|
||||
2298414396
|
||||
2275744344
|
||||
2264583342
|
||||
7754463344
|
||||
3754469433
|
||||
3354452433
|
||||
|
||||
After step 7:
|
||||
67<em>0</em>7366222
|
||||
4377366333
|
||||
4475555827
|
||||
34966557<em>0</em>9
|
||||
35<em>00</em>6256<em>0</em>9
|
||||
35<em>0</em>9955566
|
||||
3486694453
|
||||
8865585555
|
||||
486558<em>0</em>644
|
||||
4465574644
|
||||
|
||||
After step 8:
|
||||
7818477333
|
||||
5488477444
|
||||
5697666949
|
||||
46<em>0</em>876683<em>0</em>
|
||||
473494673<em>0</em>
|
||||
474<em>00</em>97688
|
||||
69<em>0000</em>7564
|
||||
<em>000000</em>9666
|
||||
8<em>00000</em>4755
|
||||
68<em>0000</em>7755
|
||||
|
||||
After step 9:
|
||||
9<em>0</em>6<em>0000</em>644
|
||||
78<em>00000</em>976
|
||||
69<em>000000</em>8<em>0</em>
|
||||
584<em>00000</em>82
|
||||
5858<em>0000</em>93
|
||||
69624<em>00000</em>
|
||||
8<em>0</em>2125<em>000</em>9
|
||||
222113<em>000</em>9
|
||||
9111128<em>0</em>97
|
||||
7911119976
|
||||
|
||||
After step 10:
|
||||
<em>0</em>481112976
|
||||
<em>00</em>31112<em>00</em>9
|
||||
<em>00</em>411125<em>0</em>4
|
||||
<em>00</em>811114<em>0</em>6
|
||||
<em>00</em>991113<em>0</em>6
|
||||
<em>00</em>93511233
|
||||
<em>0</em>44236113<em>0</em>
|
||||
553225235<em>0</em>
|
||||
<em>0</em>53225<em>0</em>6<em>00</em>
|
||||
<em>00</em>3224<em>0000</em>
|
||||
</code></pre>
|
||||
|
||||
<p>After step 10, there have been a total of <code>204</code> flashes. Fast forwarding, here is the same configuration every 10 steps:</p>
|
||||
|
||||
<pre><code>After step 20:
|
||||
3936556452
|
||||
56865568<em>0</em>6
|
||||
449655569<em>0</em>
|
||||
444865558<em>0</em>
|
||||
445686557<em>0</em>
|
||||
568<em>00</em>86577
|
||||
7<em>00000</em>9896
|
||||
<em>0000000</em>344
|
||||
6<em>000000</em>364
|
||||
46<em>0000</em>9543
|
||||
|
||||
After step 30:
|
||||
<em>0</em>643334118
|
||||
4253334611
|
||||
3374333458
|
||||
2225333337
|
||||
2229333338
|
||||
2276733333
|
||||
2754574565
|
||||
5544458511
|
||||
9444447111
|
||||
7944446119
|
||||
|
||||
After step 40:
|
||||
6211111981
|
||||
<em>0</em>421111119
|
||||
<em>00</em>42111115
|
||||
<em>000</em>3111115
|
||||
<em>000</em>3111116
|
||||
<em>00</em>65611111
|
||||
<em>0</em>532351111
|
||||
3322234597
|
||||
2222222976
|
||||
2222222762
|
||||
|
||||
After step 50:
|
||||
9655556447
|
||||
48655568<em>0</em>5
|
||||
448655569<em>0</em>
|
||||
445865558<em>0</em>
|
||||
457486557<em>0</em>
|
||||
57<em>000</em>86566
|
||||
6<em>00000</em>9887
|
||||
8<em>000000</em>533
|
||||
68<em>00000</em>633
|
||||
568<em>0000</em>538
|
||||
|
||||
After step 60:
|
||||
25333342<em>00</em>
|
||||
274333464<em>0</em>
|
||||
2264333458
|
||||
2225333337
|
||||
2225333338
|
||||
2287833333
|
||||
3854573455
|
||||
1854458611
|
||||
1175447111
|
||||
1115446111
|
||||
|
||||
After step 70:
|
||||
8211111164
|
||||
<em>0</em>421111166
|
||||
<em>00</em>42111114
|
||||
<em>000</em>4211115
|