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
|
||||||
|
<em>0000</em>211116
|
||||||
|
<em>00</em>65611111
|
||||||
|
<em>0</em>532351111
|
||||||
|
7322235117
|
||||||
|
5722223475
|
||||||
|
4572222754
|
||||||
|
|
||||||
|
After step 80:
|
||||||
|
1755555697
|
||||||
|
59655556<em>0</em>9
|
||||||
|
448655568<em>0</em>
|
||||||
|
445865558<em>0</em>
|
||||||
|
457<em>0</em>86557<em>0</em>
|
||||||
|
57<em>000</em>86566
|
||||||
|
7<em>00000</em>8666
|
||||||
|
<em>0000000</em>99<em>0</em>
|
||||||
|
<em>0000000</em>8<em>00</em>
|
||||||
|
<em>0000000000</em>
|
||||||
|
|
||||||
|
After step 90:
|
||||||
|
7433333522
|
||||||
|
2643333522
|
||||||
|
2264333458
|
||||||
|
2226433337
|
||||||
|
2222433338
|
||||||
|
2287833333
|
||||||
|
2854573333
|
||||||
|
4854458333
|
||||||
|
3387779333
|
||||||
|
3333333333
|
||||||
|
|
||||||
|
After step 100:
|
||||||
|
<em>0</em>397666866
|
||||||
|
<em>0</em>749766918
|
||||||
|
<em>00</em>53976933
|
||||||
|
<em>000</em>4297822
|
||||||
|
<em>000</em>4229892
|
||||||
|
<em>00</em>53222877
|
||||||
|
<em>0</em>532222966
|
||||||
|
9322228966
|
||||||
|
7922286866
|
||||||
|
6789998766
|
||||||
|
</code></pre>
|
||||||
|
<p>After 100 steps, there have been a total of <code><em>1656</em></code> flashes.</p>
|
||||||
|
<p>Given the starting energy levels of the dumbo octopuses in your cavern, simulate 100 steps. <em>How many total flashes are there after 100 steps?</em></p>
|
||||||
|
</article><p>Your puzzle answer was <code>1721</code>.</p><article><h2 id="part2">--- Part Two ---</h2><p>It seems like the individual flashes aren't bright enough to navigate. However, you might have a better option: the flashes seem to be <em>synchronizing</em>!</p>
|
||||||
|
<p>In the example above, the first time all octopuses flash simultaneously is step <code><em>195</em></code>:</p>
|
||||||
|
<pre><code>After step 193:
|
||||||
|
5877777777
|
||||||
|
8877777777
|
||||||
|
7777777777
|
||||||
|
7777777777
|
||||||
|
7777777777
|
||||||
|
7777777777
|
||||||
|
7777777777
|
||||||
|
7777777777
|
||||||
|
7777777777
|
||||||
|
7777777777
|
||||||
|
|
||||||
|
After step 194:
|
||||||
|
6988888888
|
||||||
|
9988888888
|
||||||
|
8888888888
|
||||||
|
8888888888
|
||||||
|
8888888888
|
||||||
|
8888888888
|
||||||
|
8888888888
|
||||||
|
8888888888
|
||||||
|
8888888888
|
||||||
|
8888888888
|
||||||
|
|
||||||
|
After step 195:
|
||||||
|
<em>0000000000</em>
|
||||||
|
<em>0000000000</em>
|
||||||
|
<em>0000000000</em>
|
||||||
|
<em>0000000000</em>
|
||||||
|
<em>0000000000</em>
|
||||||
|
<em>0000000000</em>
|
||||||
|
<em>0000000000</em>
|
||||||
|
<em>0000000000</em>
|
||||||
|
<em>0000000000</em>
|
||||||
|
<em>0000000000</em>
|
||||||
|
</code></pre>
|
||||||
|
<p>If you can calculate the exact moments when the octopuses will all flash simultaneously, you should be able to navigate through the cavern. <em>What is the first step during which all octopuses flash?</em></p>
|
||||||
|
</article><p>Your puzzle answer was <code>298</code>.</p></div>
|
147
12/problem.html
Normal file
147
12/problem.html
Normal file
|
@ -0,0 +1,147 @@
|
||||||
|
|
||||||
|
<!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 12 - 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 12: Passage Pathing ---</h2><p>With your <span title="Sublime.">submarine's subterranean subsystems subsisting suboptimally</span>, the only way you're getting out of this cave anytime soon is by finding a path yourself. Not just <em>a</em> path - the only way to know if you've found the <em>best</em> path is to find <em>all</em> of them.</p>
|
||||||
|
<p>Fortunately, the sensors are still mostly working, and so you build a rough map of the remaining caves (your puzzle input). For example:</p>
|
||||||
|
<pre><code>start-A
|
||||||
|
start-b
|
||||||
|
A-c
|
||||||
|
A-b
|
||||||
|
b-d
|
||||||
|
A-end
|
||||||
|
b-end
|
||||||
|
</code></pre>
|
||||||
|
<p>This is a list of how all of the caves are connected. You start in the cave named <code>start</code>, and your destination is the cave named <code>end</code>. An entry like <code>b-d</code> means that cave <code>b</code> is connected to cave <code>d</code> - that is, you can move between them.</p>
|
||||||
|
<p>So, the above cave system looks roughly like this:</p>
|
||||||
|
<pre><code> start
|
||||||
|
/ \
|
||||||
|
c--A-----b--d
|
||||||
|
\ /
|
||||||
|
end
|
||||||
|
</code></pre>
|
||||||
|
<p>Your goal is to find the number of distinct <em>paths</em> that start at <code>start</code>, end at <code>end</code>, and don't visit small caves more than once. There are two types of caves: <em>big</em> caves (written in uppercase, like <code>A</code>) and <em>small</em> caves (written in lowercase, like <code>b</code>). It would be a waste of time to visit any small cave more than once, but big caves are large enough that it might be worth visiting them multiple times. So, all paths you find should <em>visit small caves at most once</em>, and can <em>visit big caves any number of times</em>.</p>
|
||||||
|
<p>Given these rules, there are <code><em>10</em></code> paths through this example cave system:</p>
|
||||||
|
<pre><code>start,A,b,A,c,A,end
|
||||||
|
start,A,b,A,end
|
||||||
|
start,A,b,end
|
||||||
|
start,A,c,A,b,A,end
|
||||||
|
start,A,c,A,b,end
|
||||||
|
start,A,c,A,end
|
||||||
|
start,A,end
|
||||||
|
start,b,A,c,A,end
|
||||||
|
start,b,A,end
|
||||||
|
start,b,end
|
||||||
|
</code></pre>
|
||||||
|
<p>(Each line in the above list corresponds to a single path; the caves visited by that path are listed in the order they are visited and separated by commas.)</p>
|
||||||
|
<p>Note that in this cave system, cave <code>d</code> is never visited by any path: to do so, cave <code>b</code> would need to be visited twice (once on the way to cave <code>d</code> and a second time when returning from cave <code>d</code>), and since cave <code>b</code> is small, this is not allowed.</p>
|
||||||
|
<p>Here is a slightly larger example:</p>
|
||||||
|
<pre><code>dc-end
|
||||||
|
HN-start
|
||||||
|
start-kj
|
||||||
|
dc-start
|
||||||
|
dc-HN
|
||||||
|
LN-dc
|
||||||
|
HN-end
|
||||||
|
kj-sa
|
||||||
|
kj-HN
|
||||||
|
kj-dc
|
||||||
|
</code></pre>
|
||||||
|
<p>The <code>19</code> paths through it are as follows:</p>
|
||||||
|
<pre><code>start,HN,dc,HN,end
|
||||||
|
start,HN,dc,HN,kj,HN,end
|
||||||
|
start,HN,dc,end
|
||||||
|
start,HN,dc,kj,HN,end
|
||||||
|
start,HN,end
|
||||||
|
start,HN,kj,HN,dc,HN,end
|
||||||
|
start,HN,kj,HN,dc,end
|
||||||
|
start,HN,kj,HN,end
|
||||||
|
start,HN,kj,dc,HN,end
|
||||||
|
start,HN,kj,dc,end
|
||||||
|
start,dc,HN,end
|
||||||
|
start,dc,HN,kj,HN,end
|
||||||
|
start,dc,end
|
||||||
|
start,dc,kj,HN,end
|
||||||
|
start,kj,HN,dc,HN,end
|
||||||
|
start,kj,HN,dc,end
|
||||||
|
start,kj,HN,end
|
||||||
|
start,kj,dc,HN,end
|
||||||
|
start,kj,dc,end
|
||||||
|
</code></pre>
|
||||||
|
<p>Finally, this even larger example has <code>226</code> paths through it:</p>
|
||||||
|
<pre><code>fs-end
|
||||||
|
he-DX
|
||||||
|
fs-he
|
||||||
|
start-DX
|
||||||
|
pj-DX
|
||||||
|
end-zg
|
||||||
|
zg-sl
|
||||||
|
zg-pj
|
||||||
|
pj-he
|
||||||
|
RW-he
|
||||||
|
fs-DX
|
||||||
|
pj-RW
|
||||||
|
zg-RW
|
||||||
|
start-pj
|
||||||
|
he-WI
|
||||||
|
zg-he
|
||||||
|
pj-fs
|
||||||
|
start-RW
|
||||||
|
</code></pre>
|
||||||
|
<p><em>How many paths through this cave system are there that visit small caves at most once?</em></p>
|
||||||
|
</article><p>Your puzzle answer was <code>5254</code>.</p><article><h2 id="part2">--- Part Two ---</h2><p>After reviewing the available paths, you realize you might have time to visit a single small cave <em>twice</em>. Specifically, big caves can be visited any number of times, a single small cave can be visited at most twice, and the remaining small caves can be visited at most once. However, the caves named <code>start</code> and <code>end</code> can only be visited <em>exactly once each</em>: once you leave the <code>start</code> cave, you may not return to it, and once you reach the <code>end</code> cave, the path must end immediately.</p>
|
||||||
|
<p>Now, the <code>36</code> possible paths through the first example above are:</p>
|
||||||
|
<pre><code>start,A,b,A,b,A,c,A,end
|
||||||
|
start,A,b,A,b,A,end
|
||||||
|
start,A,b,A,b,end
|
||||||
|
start,A,b,A,c,A,b,A,end
|
||||||
|
start,A,b,A,c,A,b,end
|
||||||
|
start,A,b,A,c,A,c,A,end
|
||||||
|
start,A,b,A,c,A,end
|
||||||
|
start,A,b,A,end
|
||||||
|
start,A,b,d,b,A,c,A,end
|
||||||
|
start,A,b,d,b,A,end
|
||||||
|
start,A,b,d,b,end
|
||||||
|
start,A,b,end
|
||||||
|
start,A,c,A,b,A,b,A,end
|
||||||
|
start,A,c,A,b,A,b,end
|
||||||
|
start,A,c,A,b,A,c,A,end
|
||||||
|
start,A,c,A,b,A,end
|
||||||
|
start,A,c,A,b,d,b,A,end
|
||||||
|
start,A,c,A,b,d,b,end
|
||||||
|
start,A,c,A,b,end
|
||||||
|
start,A,c,A,c,A,b,A,end
|
||||||
|
start,A,c,A,c,A,b,end
|
||||||
|
start,A,c,A,c,A,end
|
||||||
|
start,A,c,A,end
|
||||||
|
start,A,end
|
||||||
|
start,b,A,b,A,c,A,end
|
||||||
|
start,b,A,b,A,end
|
||||||
|
start,b,A,b,end
|
||||||
|
start,b,A,c,A,b,A,end
|
||||||
|
start,b,A,c,A,b,end
|
||||||
|
start,b,A,c,A,c,A,end
|
||||||
|
start,b,A,c,A,end
|
||||||
|
start,b,A,end
|
||||||
|
start,b,d,b,A,c,A,end
|
||||||
|
start,b,d,b,A,end
|
||||||
|
start,b,d,b,end
|
||||||
|
start,b,end
|
||||||
|
</code></pre>
|
||||||
|
<p>The slightly larger example above now has <code>103</code> paths through it, and the even larger example now has <code>3509</code> paths through it.</p>
|
||||||
|
<p>Given these new rules, <em>how many paths through this cave system are there?</em></p>
|
||||||
|
</article><p>Your puzzle answer was <code>149385</code>.</p></div>
|
116
13/problem.html
Normal file
116
13/problem.html
Normal file
|
@ -0,0 +1,116 @@
|
||||||
|
|
||||||
|
<!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 13 - 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 13: Transparent Origami ---</h2><p>You reach another volcanically active part of the cave. It would be nice if you could do some kind of thermal imaging so you could tell ahead of time which caves are too hot to safely enter.</p>
|
||||||
|
<p>Fortunately, the submarine seems to be equipped with a thermal camera! When you activate it, you are greeted with:</p>
|
||||||
|
<pre><code>Congratulations on your purchase! To activate this infrared thermal imaging
|
||||||
|
camera system, please enter the code found on page 1 of the manual.
|
||||||
|
</code></pre>
|
||||||
|
<p>Apparently, the Elves have never used this feature. To your surprise, you manage to find the manual; as you go to open it, page 1 falls out. It's a large sheet of <a href="https://en.wikipedia.org/wiki/Transparency_(projection)" target="_blank">transparent paper</a>! The transparent paper is marked with random dots and includes instructions on how to fold it up (your puzzle input). For example:</p>
|
||||||
|
<pre><code>6,10
|
||||||
|
0,14
|
||||||
|
9,10
|
||||||
|
0,3
|
||||||
|
10,4
|
||||||
|
4,11
|
||||||
|
6,0
|
||||||
|
6,12
|
||||||
|
4,1
|
||||||
|
0,13
|
||||||
|
10,12
|
||||||
|
3,4
|
||||||
|
3,0
|
||||||
|
8,4
|
||||||
|
1,10
|
||||||
|
2,14
|
||||||
|
8,10
|
||||||
|
9,0
|
||||||
|
|
||||||
|
fold along y=7
|
||||||
|
fold along x=5
|
||||||
|
</code></pre>
|
||||||
|
<p>The first section is a list of dots on the transparent paper. <code>0,0</code> represents the top-left coordinate. The first value, <code>x</code>, increases to the right. The second value, <code>y</code>, increases downward. So, the coordinate <code>3,0</code> is to the right of <code>0,0</code>, and the coordinate <code>0,7</code> is below <code>0,0</code>. The coordinates in this example form the following pattern, where <code>#</code> is a dot on the paper and <code>.</code> is an empty, unmarked position:</p>
|
||||||
|
<pre><code>...#..#..#.
|
||||||
|
....#......
|
||||||
|
...........
|
||||||
|
#..........
|
||||||
|
...#....#.#
|
||||||
|
...........
|
||||||
|
...........
|
||||||
|
...........
|
||||||
|
...........
|
||||||
|
...........
|
||||||
|
.#....#.##.
|
||||||
|
....#......
|
||||||
|
......#...#
|
||||||
|
#..........
|
||||||
|
#.#........
|
||||||
|
</code></pre>
|
||||||
|
<p>Then, there is a list of <em>fold instructions</em>. Each instruction indicates a line on the transparent paper and wants you to fold the paper <em>up</em> (for horizontal <code>y=...</code> lines) or <em>left</em> (for vertical <code>x=...</code> lines). In this example, the first fold instruction is <code>fold along y=7</code>, which designates the line formed by all of the positions where <code>y</code> is <code>7</code> (marked here with <code>-</code>):</p>
|
||||||
|
<pre><code>...#..#..#.
|
||||||
|
....#......
|
||||||
|
...........
|
||||||
|
#..........
|
||||||
|
...#....#.#
|
||||||
|
...........
|
||||||
|
...........
|
||||||
|
-----------
|
||||||
|
...........
|
||||||
|
...........
|
||||||
|
.#....#.##.
|
||||||
|
....#......
|
||||||
|
......#...#
|
||||||
|
#..........
|
||||||
|
#.#........
|
||||||
|
</code></pre>
|
||||||
|
<p>Because this is a horizontal line, fold the bottom half <em>up</em>. Some of the dots might end up overlapping after the fold is complete, but dots will never appear exactly on a fold line. The result of doing this fold looks like this:</p>
|
||||||
|
<pre><code>#.##..#..#.
|
||||||
|
#...#......
|
||||||
|
......#...#
|
||||||
|
#...#......
|
||||||
|
.#.#..#.###
|
||||||
|
...........
|
||||||
|
...........
|
||||||
|
</code></pre>
|
||||||
|
<p>Now, only <code>17</code> dots are visible.</p>
|
||||||
|
<p>Notice, for example, the two dots in the bottom left corner before the transparent paper is folded; after the fold is complete, those dots appear in the top left corner (at <code>0,0</code> and <code>0,1</code>). Because the paper is transparent, the dot just below them in the result (at <code>0,3</code>) remains visible, as it can be seen through the transparent paper.</p>
|
||||||
|
<p>Also notice that some dots can end up <em>overlapping</em>; in this case, the dots merge together and become a single dot.</p>
|
||||||
|
<p>The second fold instruction is <code>fold along x=5</code>, which indicates this line:</p>
|
||||||
|
<pre><code>#.##.|#..#.
|
||||||
|
#...#|.....
|
||||||
|
.....|#...#
|
||||||
|
#...#|.....
|
||||||
|
.#.#.|#.###
|
||||||
|
.....|.....
|
||||||
|
.....|.....
|
||||||
|
</code></pre>
|
||||||
|
<p>Because this is a vertical line, fold <em>left</em>:</p>
|
||||||
|
<pre><code>#####
|
||||||
|
#...#
|
||||||
|
#...#
|
||||||
|
#...#
|
||||||
|
#####
|
||||||
|
.....
|
||||||
|
.....
|
||||||
|
</code></pre>
|
||||||
|
<p>The instructions made a square!</p>
|
||||||
|
<p>The transparent paper is pretty big, so for now, focus on just completing the first fold. After the first fold in the example above, <code><em>17</em></code> dots are visible - dots that end up overlapping after the fold is completed count as a single dot.</p>
|
||||||
|
<p><em>How many dots are visible after completing just the first fold instruction on your transparent paper?</em></p>
|
||||||
|
</article><p>Your puzzle answer was <code>671</code>.</p><article><h2 id="part2">--- Part Two ---</h2><p><span title="How can you fold it that many times? You tell me, I'm not the one folding it.">Finish folding</span> the transparent paper according to the instructions. The manual says the code is always <em>eight capital letters</em>.</p>
|
||||||
|
<p><em>What code do you use to activate the infrared thermal imaging camera system?</em></p>
|
||||||
|
</article><p>Your puzzle answer was <code>PCPHARKL</code>.</p></div>
|
65
14/problem.html
Normal file
65
14/problem.html
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
|
||||||
|
<!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 14 - 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 14: Extended Polymerization ---</h2><p>The incredible pressures at this depth are starting to put a strain on your submarine. The submarine has <a href="https://en.wikipedia.org/wiki/Polymerization" target="_blank">polymerization</a> equipment that would produce suitable materials to reinforce the submarine, and the nearby volcanically-active caves should even have the necessary input elements in sufficient quantities.</p>
|
||||||
|
<p>The submarine manual contains <span title="HO
|
||||||
|
|
||||||
|
HO -> OH">instructions</span> for finding the optimal polymer formula; specifically, it offers a <em>polymer template</em> and a list of <em>pair insertion</em> rules (your puzzle input). You just need to work out what polymer would result after repeating the pair insertion process a few times.</p>
|
||||||
|
<p>For example:</p>
|
||||||
|
<pre><code>NNCB
|
||||||
|
|
||||||
|
CH -> B
|
||||||
|
HH -> N
|
||||||
|
CB -> H
|
||||||
|
NH -> C
|
||||||
|
HB -> C
|
||||||
|
HC -> B
|
||||||
|
HN -> C
|
||||||
|
NN -> C
|
||||||
|
BH -> H
|
||||||
|
NC -> B
|
||||||
|
NB -> B
|
||||||
|
BN -> B
|
||||||
|
BB -> N
|
||||||
|
BC -> B
|
||||||
|
CC -> N
|
||||||
|
CN -> C
|
||||||
|
</code></pre>
|
||||||
|
<p>The first line is the <em>polymer template</em> - this is the starting point of the process.</p>
|
||||||
|
<p>The following section defines the <em>pair insertion</em> rules. A rule like <code>AB -> C</code> means that when elements <code>A</code> and <code>B</code> are immediately adjacent, element <code>C</code> should be inserted between them. These insertions all happen simultaneously.</p>
|
||||||
|
<p>So, starting with the polymer template <code>NNCB</code>, the first step simultaneously considers all three pairs:</p>
|
||||||
|
<ul>
|
||||||
|
<li>The first pair (<code>NN</code>) matches the rule <code>NN -> C</code>, so element <code><em>C</em></code> is inserted between the first <code>N</code> and the second <code>N</code>.</li>
|
||||||
|
<li>The second pair (<code>NC</code>) matches the rule <code>NC -> B</code>, so element <code><em>B</em></code> is inserted between the <code>N</code> and the <code>C</code>.</li>
|
||||||
|
<li>The third pair (<code>CB</code>) matches the rule <code>CB -> H</code>, so element <code><em>H</em></code> is inserted between the <code>C</code> and the <code>B</code>.</li>
|
||||||
|
</ul>
|
||||||
|
<p>Note that these pairs overlap: the second element of one pair is the first element of the next pair. Also, because all pairs are considered simultaneously, inserted elements are not considered to be part of a pair until the next step.</p>
|
||||||
|
<p>After the first step of this process, the polymer becomes <code>N<em>C</em>N<em>B</em>C<em>H</em>B</code>.</p>
|
||||||
|
<p>Here are the results of a few steps using the above rules:</p>
|
||||||
|
<pre><code>Template: NNCB
|
||||||
|
After step 1: NCNBCHB
|
||||||
|
After step 2: NBCCNBBBCBHCB
|
||||||
|
After step 3: NBBBCNCCNBBNBNBBCHBHHBCHB
|
||||||
|
After step 4: NBBNBNBBCCNBCNCCNBBNBBNBBBNBBNBBCBHCBHHNHCBBCBHCB
|
||||||
|
</code></pre>
|
||||||
|
<p>This polymer grows quickly. After step 5, it has length 97; After step 10, it has length 3073. After step 10, <code>B</code> occurs 1749 times, <code>C</code> occurs 298 times, <code>H</code> occurs 161 times, and <code>N</code> occurs 865 times; taking the quantity of the most common element (<code>B</code>, 1749) and subtracting the quantity of the least common element (<code>H</code>, 161) produces <code>1749 - 161 = <em>1588</em></code>.</p>
|
||||||
|
<p>Apply 10 steps of pair insertion to the polymer template and find the most and least common elements in the result. <em>What do you get if you take the quantity of the most common element and subtract the quantity of the least common element?</em></p>
|
||||||
|
</article><p>Your puzzle answer was <code>2360</code>.</p><article><h2 id="part2">--- Part Two ---</h2><p>The resulting polymer isn't nearly strong enough to reinforce the submarine. You'll need to run more steps of the pair insertion process; a total of <em>40 steps</em> should do it.</p>
|
||||||
|
<p>In the above example, the most common element is <code>B</code> (occurring <code>2192039569602</code> times) and the least common element is <code>H</code> (occurring <code>3849876073</code> times); subtracting these produces <code><em>2188189693529</em></code>.</p>
|
||||||
|
<p>Apply <em>40</em> steps of pair insertion to the polymer template and find the most and least common elements in the result. <em>What do you get if you take the quantity of the most common element and subtract the quantity of the least common element?</em></p>
|
||||||
|
</article><p>Your puzzle answer was <code>2967977072188</code>.</p></div>
|
170
15/problem.html
Normal file
170
15/problem.html
Normal file
|
@ -0,0 +1,170 @@
|
||||||
|
|
||||||
|
<!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 15 - 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 15: Chiton ---</h2><p>You've almost reached the exit of the cave, but the walls are getting closer together. Your submarine can barely still fit, though; the main problem is that the walls of the cave are covered in <a href="https://en.wikipedia.org/wiki/Chiton" target="_blank">chitons</a>, and it would be best not to bump any of them.</p>
|
||||||
|
<p>The cavern is large, but has a very low ceiling, restricting your motion to two dimensions. The shape of the cavern resembles a square; a quick scan of chiton density produces a map of <em>risk level</em> throughout the cave (your puzzle input). For example:</p>
|
||||||
|
<pre><code>1163751742
|
||||||
|
1381373672
|
||||||
|
2136511328
|
||||||
|
3694931569
|
||||||
|
7463417111
|
||||||
|
1319128137
|
||||||
|
1359912421
|
||||||
|
3125421639
|
||||||
|
1293138521
|
||||||
|
2311944581
|
||||||
|
</code></pre>
|
||||||
|
<p>You start in the top left position, your destination is the bottom right position, and you <span title="Can't go diagonal until we can repair the caterpillar unit. Could be the liquid helium or the superconductors.">cannot move diagonally</span>. The number at each position is its <em>risk level</em>; to determine the total risk of an entire path, add up the risk levels of each position you <em>enter</em> (that is, don't count the risk level of your starting position unless you enter it; leaving it adds no risk to your total).</p>
|
||||||
|
<p>Your goal is to find a path with the <em>lowest total risk</em>. In this example, a path with the lowest total risk is highlighted here:</p>
|
||||||
|
<pre><code><em>1</em>163751742
|
||||||
|
<em>1</em>381373672
|
||||||
|
<em>2136511</em>328
|
||||||
|
369493<em>15</em>69
|
||||||
|
7463417<em>1</em>11
|
||||||
|
1319128<em>13</em>7
|
||||||
|
13599124<em>2</em>1
|
||||||
|
31254216<em>3</em>9
|
||||||
|
12931385<em>21</em>
|
||||||
|
231194458<em>1</em>
|
||||||
|
</code></pre>
|
||||||
|
<p>The total risk of this path is <code><em>40</em></code> (the starting position is never entered, so its risk is not counted).</p>
|
||||||
|
<p><em>What is the lowest total risk of any path from the top left to the bottom right?</em></p>
|
||||||
|
</article>
|
||||||
|
<p>Your puzzle answer was <code>410</code>.</p><article><h2 id="part2">--- Part Two ---</h2><p>Now that you know how to find low-risk paths in the cave, you can try to find your way out.</p>
|
||||||
|
<p>The entire cave is actually <em>five times larger in both dimensions</em> than you thought; the area you originally scanned is just one tile in a 5x5 tile area that forms the full map. Your original map tile repeats to the right and downward; each time the tile repeats to the right or downward, all of its risk levels <em>are 1 higher</em> than the tile immediately up or left of it. However, risk levels above <code>9</code> wrap back around to <code>1</code>. So, if your original map had some position with a risk level of <code>8</code>, then that same position on each of the 25 total tiles would be as follows:</p>
|
||||||
|
<pre><code>8 9 1 2 3
|
||||||
|
9 1 2 3 4
|
||||||
|
1 2 3 4 5
|
||||||
|
2 3 4 5 6
|
||||||
|
3 4 5 6 7
|
||||||
|
</code></pre>
|
||||||
|
<p>Each single digit above corresponds to the example position with a value of <code>8</code> on the top-left tile. Because the full map is actually five times larger in both dimensions, that position appears a total of 25 times, once in each duplicated tile, with the values shown above.</p>
|
||||||
|
<p>Here is the full five-times-as-large version of the first example above, with the original map in the top left corner highlighted:</p>
|
||||||
|
<pre><code><em>1163751742</em>2274862853338597396444961841755517295286
|
||||||
|
<em>1381373672</em>2492484783351359589446246169155735727126
|
||||||
|
<em>2136511328</em>3247622439435873354154698446526571955763
|
||||||
|
<em>3694931569</em>4715142671582625378269373648937148475914
|
||||||
|
<em>7463417111</em>8574528222968563933317967414442817852555
|
||||||
|
<em>1319128137</em>2421239248353234135946434524615754563572
|
||||||
|
<em>1359912421</em>2461123532357223464346833457545794456865
|
||||||
|
<em>3125421639</em>4236532741534764385264587549637569865174
|
||||||
|
<em>1293138521</em>2314249632342535174345364628545647573965
|
||||||
|
<em>2311944581</em>3422155692453326671356443778246755488935
|
||||||
|
22748628533385973964449618417555172952866628316397
|
||||||
|
24924847833513595894462461691557357271266846838237
|
||||||
|
32476224394358733541546984465265719557637682166874
|
||||||
|
47151426715826253782693736489371484759148259586125
|
||||||
|
85745282229685639333179674144428178525553928963666
|
||||||
|
24212392483532341359464345246157545635726865674683
|
||||||
|
24611235323572234643468334575457944568656815567976
|
||||||
|
42365327415347643852645875496375698651748671976285
|
||||||
|
23142496323425351743453646285456475739656758684176
|
||||||
|
34221556924533266713564437782467554889357866599146
|
||||||
|
33859739644496184175551729528666283163977739427418
|
||||||
|
35135958944624616915573572712668468382377957949348
|
||||||
|
43587335415469844652657195576376821668748793277985
|
||||||
|
58262537826937364893714847591482595861259361697236
|
||||||
|
96856393331796741444281785255539289636664139174777
|
||||||
|
35323413594643452461575456357268656746837976785794
|
||||||
|
35722346434683345754579445686568155679767926678187
|
||||||
|
53476438526458754963756986517486719762859782187396
|
||||||
|
34253517434536462854564757396567586841767869795287
|
||||||
|
45332667135644377824675548893578665991468977611257
|
||||||
|
44961841755517295286662831639777394274188841538529
|
||||||
|
46246169155735727126684683823779579493488168151459
|
||||||
|
54698446526571955763768216687487932779859814388196
|
||||||
|
69373648937148475914825958612593616972361472718347
|
||||||
|
17967414442817852555392896366641391747775241285888
|
||||||
|
46434524615754563572686567468379767857948187896815
|
||||||
|
46833457545794456865681556797679266781878137789298
|
||||||
|
64587549637569865174867197628597821873961893298417
|
||||||
|
45364628545647573965675868417678697952878971816398
|
||||||
|
56443778246755488935786659914689776112579188722368
|
||||||
|
55172952866628316397773942741888415385299952649631
|
||||||
|
57357271266846838237795794934881681514599279262561
|
||||||
|
65719557637682166874879327798598143881961925499217
|
||||||
|
71484759148259586125936169723614727183472583829458
|
||||||
|
28178525553928963666413917477752412858886352396999
|
||||||
|
57545635726865674683797678579481878968159298917926
|
||||||
|
57944568656815567976792667818781377892989248891319
|
||||||
|
75698651748671976285978218739618932984172914319528
|
||||||
|
56475739656758684176786979528789718163989182927419
|
||||||
|
67554889357866599146897761125791887223681299833479
|
||||||
|
</code></pre>
|
||||||
|
<p>Equipped with the full map, you can now find a path from the top left corner to the bottom right corner with the lowest total risk:</p>
|
||||||
|
<pre><code><em>1</em>1637517422274862853338597396444961841755517295286
|
||||||
|
<em>1</em>3813736722492484783351359589446246169155735727126
|
||||||
|
<em>2</em>1365113283247622439435873354154698446526571955763
|
||||||
|
<em>3</em>6949315694715142671582625378269373648937148475914
|
||||||
|
<em>7</em>4634171118574528222968563933317967414442817852555
|
||||||
|
<em>1</em>3191281372421239248353234135946434524615754563572
|
||||||
|
<em>1</em>3599124212461123532357223464346833457545794456865
|
||||||
|
<em>3</em>1254216394236532741534764385264587549637569865174
|
||||||
|
<em>1</em>2931385212314249632342535174345364628545647573965
|
||||||
|
<em>2</em>3119445813422155692453326671356443778246755488935
|
||||||
|
<em>2</em>2748628533385973964449618417555172952866628316397
|
||||||
|
<em>2</em>4924847833513595894462461691557357271266846838237
|
||||||
|
<em>324</em>76224394358733541546984465265719557637682166874
|
||||||
|
47<em>15</em>1426715826253782693736489371484759148259586125
|
||||||
|
857<em>4</em>5282229685639333179674144428178525553928963666
|
||||||
|
242<em>1</em>2392483532341359464345246157545635726865674683
|
||||||
|
246<em>1123532</em>3572234643468334575457944568656815567976
|
||||||
|
423653274<em>1</em>5347643852645875496375698651748671976285
|
||||||
|
231424963<em>2342</em>5351743453646285456475739656758684176
|
||||||
|
342215569245<em>332</em>66713564437782467554889357866599146
|
||||||
|
33859739644496<em>1</em>84175551729528666283163977739427418
|
||||||
|
35135958944624<em>61</em>6915573572712668468382377957949348
|
||||||
|
435873354154698<em>44</em>652657195576376821668748793277985
|
||||||
|
5826253782693736<em>4</em>893714847591482595861259361697236
|
||||||
|
9685639333179674<em>1</em>444281785255539289636664139174777
|
||||||
|
3532341359464345<em>2461</em>575456357268656746837976785794
|
||||||
|
3572234643468334575<em>4</em>579445686568155679767926678187
|
||||||
|
5347643852645875496<em>3</em>756986517486719762859782187396
|
||||||
|
3425351743453646285<em>4564</em>757396567586841767869795287
|
||||||
|
4533266713564437782467<em>554</em>8893578665991468977611257
|
||||||
|
449618417555172952866628<em>3163</em>9777394274188841538529
|
||||||
|
462461691557357271266846838<em>2</em>3779579493488168151459
|
||||||
|
546984465265719557637682166<em>8</em>7487932779859814388196
|
||||||
|
693736489371484759148259586<em>125</em>93616972361472718347
|
||||||
|
17967414442817852555392896366<em>6413</em>91747775241285888
|
||||||
|
46434524615754563572686567468379<em>7</em>67857948187896815
|
||||||
|
46833457545794456865681556797679<em>26</em>6781878137789298
|
||||||
|
645875496375698651748671976285978<em>21</em>873961893298417
|
||||||
|
4536462854564757396567586841767869<em>7</em>952878971816398
|
||||||
|
5644377824675548893578665991468977<em>6112</em>579188722368
|
||||||
|
5517295286662831639777394274188841538<em>5</em>299952649631
|
||||||
|
5735727126684683823779579493488168151<em>4</em>599279262561
|
||||||
|
6571955763768216687487932779859814388<em>1</em>961925499217
|
||||||
|
7148475914825958612593616972361472718<em>34725</em>83829458
|
||||||
|
28178525553928963666413917477752412858886<em>3</em>52396999
|
||||||
|
57545635726865674683797678579481878968159<em>2</em>98917926
|
||||||
|
57944568656815567976792667818781377892989<em>24</em>8891319
|
||||||
|
756986517486719762859782187396189329841729<em>1431</em>9528
|
||||||
|
564757396567586841767869795287897181639891829<em>2</em>7419
|
||||||
|
675548893578665991468977611257918872236812998<em>33479</em>
|
||||||
|
</code></pre>
|
||||||
|
<p>The total risk of this path is <code><em>315</em></code> (the starting position is still never entered, so its risk is not counted).</p>
|
||||||
|
<p>Using the full map, <em>what is the lowest total risk of any path from the top left to the bottom right?</em></p>
|
||||||
|
</article>
|
||||||
|
<p>Your puzzle answer was <code>2809</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/15/input" target="_blank">get your puzzle input</a>.</p>
|
||||||
|
<p>You can also this puzzle.</p>
|
||||||
|
</div></div>
|
122
16/problem.html
Normal file
122
16/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 16 - 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 16: Packet Decoder ---</h2><p>As you leave the cave and reach open waters, you receive a transmission from the Elves back on the ship.</p>
|
||||||
|
<p>The transmission was sent using the Buoyancy Interchange Transmission System (<span title="Just be glad it wasn't sent using the BuoyancY Transmission Encoding System.">BITS</span>), a method of packing numeric expressions into a binary sequence. Your submarine's computer has saved the transmission in <a href="https://en.wikipedia.org/wiki/Hexadecimal" target="_blank">hexadecimal</a> (your puzzle input).</p>
|
||||||
|
<p>The first step of decoding the message is to convert the hexadecimal representation into binary. Each character of hexadecimal corresponds to four bits of binary data:</p>
|
||||||
|
<pre><code>0 = 0000
|
||||||
|
1 = 0001
|
||||||
|
2 = 0010
|
||||||
|
3 = 0011
|
||||||
|
4 = 0100
|
||||||
|
5 = 0101
|
||||||
|
6 = 0110
|
||||||
|
7 = 0111
|
||||||
|
8 = 1000
|
||||||
|
9 = 1001
|
||||||
|
A = 1010
|
||||||
|
B = 1011
|
||||||
|
C = 1100
|
||||||
|
D = 1101
|
||||||
|
E = 1110
|
||||||
|
F = 1111
|
||||||
|
</code></pre>
|
||||||
|
<p>The BITS transmission contains a single <em>packet</em> at its outermost layer which itself contains many other packets. The hexadecimal representation of this packet might encode a few extra <code>0</code> bits at the end; these are not part of the transmission and should be ignored.</p>
|
||||||
|
<p>Every packet begins with a standard header: the first three bits encode the packet <em>version</em>, and the next three bits encode the packet <em>type ID</em>. These two values are numbers; all numbers encoded in any packet are represented as binary with the most significant bit first. For example, a version encoded as the binary sequence <code>100</code> represents the number <code>4</code>.</p>
|
||||||
|
<p>Packets with type ID <code>4</code> represent a <em>literal value</em>. Literal value packets encode a single binary number. To do this, the binary number is padded with leading zeroes until its length is a multiple of four bits, and then it is broken into groups of four bits. Each group is prefixed by a <code>1</code> bit except the last group, which is prefixed by a <code>0</code> bit. These groups of five bits immediately follow the packet header. For example, the hexadecimal string <code>D2FE28</code> becomes:</p>
|
||||||
|
<pre><code>110100101111111000101000
|
||||||
|
VVVTTTAAAAABBBBBCCCCC
|
||||||
|
</code></pre>
|
||||||
|
<p>Below each bit is a label indicating its purpose:</p>
|
||||||
|
<ul>
|
||||||
|
<li>The three bits labeled <code>V</code> (<code>110</code>) are the packet version, <code>6</code>.</li>
|
||||||
|
<li>The three bits labeled <code>T</code> (<code>100</code>) are the packet type ID, <code>4</code>, which means the packet is a literal value.</li>
|
||||||
|
<li>The five bits labeled <code>A</code> (<code>10111</code>) start with a <code>1</code> (not the last group, keep reading) and contain the first four bits of the number, <code>0111</code>.</li>
|
||||||
|
<li>The five bits labeled <code>B</code> (<code>11110</code>) start with a <code>1</code> (not the last group, keep reading) and contain four more bits of the number, <code>1110</code>.</li>
|
||||||
|
<li>The five bits labeled <code>C</code> (<code>00101</code>) start with a <code>0</code> (last group, end of packet) and contain the last four bits of the number, <code>0101</code>.</li>
|
||||||
|
<li>The three unlabeled <code>0</code> bits at the end are extra due to the hexadecimal representation and should be ignored.</li>
|
||||||
|
</ul>
|
||||||
|
<p>So, this packet represents a literal value with binary representation <code>011111100101</code>, which is <code>2021</code> in decimal.</p>
|
||||||
|
<p>Every other type of packet (any packet with a type ID other than <code>4</code>) represent an <em>operator</em> that performs some calculation on one or more sub-packets contained within. Right now, the specific operations aren't important; focus on parsing the hierarchy of sub-packets.</p>
|
||||||
|
<p>An operator packet contains one or more packets. To indicate which subsequent binary data represents its sub-packets, an operator packet can use one of two modes indicated by the bit immediately after the packet header; this is called the <em>length type ID</em>:</p>
|
||||||
|
<ul>
|
||||||
|
<li>If the length type ID is <code>0</code>, then the next <em>15</em> bits are a number that represents the <em>total length in bits</em> of the sub-packets contained by this packet.</li>
|
||||||
|
<li>If the length type ID is <code>1</code>, then the next <em>11</em> bits are a number that represents the <em>number of sub-packets immediately contained</em> by this packet.</li>
|
||||||
|
</ul>
|
||||||
|
<p>Finally, after the length type ID bit and the 15-bit or 11-bit field, the sub-packets appear.</p>
|
||||||
|
<p>For example, here is an operator packet (hexadecimal string <code>38006F45291200</code>) with length type ID <code>0</code> that contains two sub-packets:</p>
|
||||||
|
<pre><code>00111000000000000110111101000101001010010001001000000000
|
||||||
|
VVVTTTILLLLLLLLLLLLLLLAAAAAAAAAAABBBBBBBBBBBBBBBB
|
||||||
|
</code></pre>
|
||||||
|
<ul>
|
||||||
|
<li>The three bits labeled <code>V</code> (<code>001</code>) are the packet version, <code>1</code>.</li>
|
||||||
|
<li>The three bits labeled <code>T</code> (<code>110</code>) are the packet type ID, <code>6</code>, which means the packet is an operator.</li>
|
||||||
|
<li>The bit labeled <code>I</code> (<code>0</code>) is the length type ID, which indicates that the length is a 15-bit number representing the number of bits in the sub-packets.</li>
|
||||||
|
<li>The 15 bits labeled <code>L</code> (<code>000000000011011</code>) contain the length of the sub-packets in bits, <code>27</code>.</li>
|
||||||
|
<li>The 11 bits labeled <code>A</code> contain the first sub-packet, a literal value representing the number <code>10</code>.</li>
|
||||||
|
<li>The 16 bits labeled <code>B</code> contain the second sub-packet, a literal value representing the number <code>20</code>.</li>
|
||||||
|
</ul>
|
||||||
|
<p>After reading 11 and 16 bits of sub-packet data, the total length indicated in <code>L</code> (27) is reached, and so parsing of this packet stops.</p>
|
||||||
|
<p>As another example, here is an operator packet (hexadecimal string <code>EE00D40C823060</code>) with length type ID <code>1</code> that contains three sub-packets:</p>
|
||||||
|
<pre><code>11101110000000001101010000001100100000100011000001100000
|
||||||
|
VVVTTTILLLLLLLLLLLAAAAAAAAAAABBBBBBBBBBBCCCCCCCCCCC
|
||||||
|
</code></pre>
|
||||||
|
<ul>
|
||||||
|
<li>The three bits labeled <code>V</code> (<code>111</code>) are the packet version, <code>7</code>.</li>
|
||||||
|
<li>The three bits labeled <code>T</code> (<code>011</code>) are the packet type ID, <code>3</code>, which means the packet is an operator.</li>
|
||||||
|
<li>The bit labeled <code>I</code> (<code>1</code>) is the length type ID, which indicates that the length is a 11-bit number representing the number of sub-packets.</li>
|
||||||
|
<li>The 11 bits labeled <code>L</code> (<code>00000000011</code>) contain the number of sub-packets, <code>3</code>.</li>
|
||||||
|
<li>The 11 bits labeled <code>A</code> contain the first sub-packet, a literal value representing the number <code>1</code>.</li>
|
||||||
|
<li>The 11 bits labeled <code>B</code> contain the second sub-packet, a literal value representing the number <code>2</code>.</li>
|
||||||
|
<li>The 11 bits labeled <code>C</code> contain the third sub-packet, a literal value representing the number <code>3</code>.</li>
|
||||||
|
</ul>
|
||||||
|
<p>After reading 3 complete sub-packets, the number of sub-packets indicated in <code>L</code> (3) is reached, and so parsing of this packet stops.</p>
|
||||||
|
<p>For now, parse the hierarchy of the packets throughout the transmission and <em>add up all of the version numbers</em>.</p>
|
||||||
|
<p>Here are a few more examples of hexadecimal-encoded transmissions:</p>
|
||||||
|
<ul>
|
||||||
|
<li><code>8A004A801A8002F478</code> represents an operator packet (version 4) which contains an operator packet (version 1) which contains an operator packet (version 5) which contains a literal value (version 6); this packet has a version sum of <code><em>16</em></code>.</li>
|
||||||
|
<li><code>620080001611562C8802118E34</code> represents an operator packet (version 3) which contains two sub-packets; each sub-packet is an operator packet that contains two literal values. This packet has a version sum of <code><em>12</em></code>.</li>
|
||||||
|
<li><code>C0015000016115A2E0802F182340</code> has the same structure as the previous example, but the outermost packet uses a different length type ID. This packet has a version sum of <code><em>23</em></code>.</li>
|
||||||
|
<li><code>A0016C880162017C3686B18A3D4780</code> is an operator packet that contains an operator packet that contains an operator packet that contains five literal values; it has a version sum of <code><em>31</em></code>.</li>
|
||||||
|
</ul>
|
||||||
|
<p>Decode the structure of your hexadecimal-encoded BITS transmission; <em>what do you get if you add up the version numbers in all packets?</em></p>
|
||||||
|
</article><p>Your puzzle answer was <code>925</code>.</p><article><h2 id="part2">--- Part Two ---</h2><p>Now that you have the structure of your transmission decoded, you can calculate the value of the expression it represents.</p>
|
||||||
|
<p>Literal values (type ID <code>4</code>) represent a single number as described above. The remaining type IDs are more interesting:</p>
|
||||||
|
<ul>
|
||||||
|
<li>Packets with type ID <code>0</code> are <em>sum</em> packets - their value is the sum of the values of their sub-packets. If they only have a single sub-packet, their value is the value of the sub-packet.</li>
|
||||||
|
<li>Packets with type ID <code>1</code> are <em>product</em> packets - their value is the result of multiplying together the values of their sub-packets. If they only have a single sub-packet, their value is the value of the sub-packet.</li>
|
||||||
|
<li>Packets with type ID <code>2</code> are <em>minimum</em> packets - their value is the minimum of the values of their sub-packets.</li>
|
||||||
|
<li>Packets with type ID <code>3</code> are <em>maximum</em> packets - their value is the maximum of the values of their sub-packets.</li>
|
||||||
|
<li>Packets with type ID <code>5</code> are <em>greater than</em> packets - their value is <em>1</em> if the value of the first sub-packet is greater than the value of the second sub-packet; otherwise, their value is <em>0</em>. These packets always have exactly two sub-packets.</li>
|
||||||
|
<li>Packets with type ID <code>6</code> are <em>less than</em> packets - their value is <em>1</em> if the value of the first sub-packet is less than the value of the second sub-packet; otherwise, their value is <em>0</em>. These packets always have exactly two sub-packets.</li>
|
||||||
|
<li>Packets with type ID <code>7</code> are <em>equal to</em> packets - their value is <em>1</em> if the value of the first sub-packet is equal to the value of the second sub-packet; otherwise, their value is <em>0</em>. These packets always have exactly two sub-packets.</li>
|
||||||
|
</ul>
|
||||||
|
<p>Using these rules, you can now work out the value of the outermost packet in your BITS transmission.</p>
|
||||||
|
<p>For example:</p>
|
||||||
|
<ul>
|
||||||
|
<li><code>C200B40A82</code> finds the sum of <code>1</code> and <code>2</code>, resulting in the value <code><em>3</em></code>.</li>
|
||||||
|
<li><code>04005AC33890</code> finds the product of <code>6</code> and <code>9</code>, resulting in the value <code><em>54</em></code>.</li>
|
||||||
|
<li><code>880086C3E88112</code> finds the minimum of <code>7</code>, <code>8</code>, and <code>9</code>, resulting in the value <code><em>7</em></code>.</li>
|
||||||
|
<li><code>CE00C43D881120</code> finds the maximum of <code>7</code>, <code>8</code>, and <code>9</code>, resulting in the value <code><em>9</em></code>.</li>
|
||||||
|
<li><code>D8005AC2A8F0</code> produces <code>1</code>, because <code>5</code> is less than <code>15</code>.</li>
|
||||||
|
<li><code>F600BC2D8F</code> produces <code>0</code>, because <code>5</code> is not greater than <code>15</code>.</li>
|
||||||
|
<li><code>9C005AC2F8F0</code> produces <code>0</code>, because <code>5</code> is not equal to <code>15</code>.</li>
|
||||||
|
<li><code>9C0141080250320F1802104A08</code> produces <code>1</code>, because <code>1</code> + <code>3</code> = <code>2</code> * <code>2</code>.</li>
|
||||||
|
</ul>
|
||||||
|
<p><em>What do you get if you evaluate the expression represented by your hexadecimal-encoded BITS transmission?</em></p>
|
||||||
|
</article><p>Your puzzle answer was <code>342997120375</code>.</p></div>
|
128
17/problem.html
Normal file
128
17/problem.html
Normal file
|
@ -0,0 +1,128 @@
|
||||||
|
|
||||||
|
<!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 17 - 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 17: Trick Shot ---</h2><p>You finally decode the Elves' message. <code><span title="Maybe you need to turn the message 90 degrees counterclockwise?">HI</span></code>, the message says. You continue searching for the sleigh keys.</p>
|
||||||
|
<p>Ahead of you is what appears to be a large <a href="https://en.wikipedia.org/wiki/Oceanic_trench" target="_blank">ocean trench</a>. Could the keys have fallen into it? You'd better send a probe to investigate.</p>
|
||||||
|
<p>The probe launcher on your submarine can fire the probe with any <a href="https://en.wikipedia.org/wiki/Integer" target="_blank">integer</a> velocity in the <code>x</code> (forward) and <code>y</code> (upward, or downward if negative) directions. For example, an initial <code>x,y</code> velocity like <code>0,10</code> would fire the probe straight up, while an initial velocity like <code>10,-1</code> would fire the probe forward at a slight downward angle.</p>
|
||||||
|
<p>The probe's <code>x,y</code> position starts at <code>0,0</code>. Then, it will follow some trajectory by moving in <em>steps</em>. On each step, these changes occur in the following order:</p>
|
||||||
|
<ul>
|
||||||
|
<li>The probe's <code>x</code> position increases by its <code>x</code> velocity.</li>
|
||||||
|
<li>The probe's <code>y</code> position increases by its <code>y</code> velocity.</li>
|
||||||
|
<li>Due to drag, the probe's <code>x</code> velocity changes by <code>1</code> toward the value <code>0</code>; that is, it decreases by <code>1</code> if it is greater than <code>0</code>, increases by <code>1</code> if it is less than <code>0</code>, or does not change if it is already <code>0</code>.</li>
|
||||||
|
<li>Due to gravity, the probe's <code>y</code> velocity decreases by <code>1</code>.</li>
|
||||||
|
</ul>
|
||||||
|
<p>For the probe to successfully make it into the trench, the probe must be on some trajectory that causes it to be within a <em>target area</em> after any step. The submarine computer has already calculated this target area (your puzzle input). For example:</p>
|
||||||
|
<pre><code>target area: x=20..30, y=-10..-5</code></pre>
|
||||||
|
<p>This target area means that you need to find initial <code>x,y</code> velocity values such that after any step, the probe's <code>x</code> position is at least <code>20</code> and at most <code>30</code>, <em>and</em> the probe's <code>y</code> position is at least <code>-10</code> and at most <code>-5</code>.</p>
|
||||||
|
<p>Given this target area, one initial velocity that causes the probe to be within the target area after any step is <code>7,2</code>:</p>
|
||||||
|
<pre><code>.............#....#............
|
||||||
|
.......#..............#........
|
||||||
|
...............................
|
||||||
|
S........................#.....
|
||||||
|
...............................
|
||||||
|
...............................
|
||||||
|
...........................#...
|
||||||
|
...............................
|
||||||
|
....................TTTTTTTTTTT
|
||||||
|
....................TTTTTTTTTTT
|
||||||
|
....................TTTTTTTT#TT
|
||||||
|
....................TTTTTTTTTTT
|
||||||
|
....................TTTTTTTTTTT
|
||||||
|
....................TTTTTTTTTTT
|
||||||
|
</code></pre>
|
||||||
|
<p>In this diagram, <code>S</code> is the probe's initial position, <code>0,0</code>. The <code>x</code> coordinate increases to the right, and the <code>y</code> coordinate increases upward. In the bottom right, positions that are within the target area are shown as <code>T</code>. After each step (until the target area is reached), the position of the probe is marked with <code>#</code>. (The bottom-right <code>#</code> is both a position the probe reaches and a position in the target area.)</p>
|
||||||
|
<p>Another initial velocity that causes the probe to be within the target area after any step is <code>6,3</code>:</p>
|
||||||
|
<pre><code>...............#..#............
|
||||||
|
...........#........#..........
|
||||||
|
...............................
|
||||||
|
......#..............#.........
|
||||||
|
...............................
|
||||||
|
...............................
|
||||||
|
S....................#.........
|
||||||
|
...............................
|
||||||
|
...............................
|
||||||
|
...............................
|
||||||
|
.....................#.........
|
||||||
|
....................TTTTTTTTTTT
|
||||||
|
....................TTTTTTTTTTT
|
||||||
|
....................TTTTTTTTTTT
|
||||||
|
....................TTTTTTTTTTT
|
||||||
|
....................T#TTTTTTTTT
|
||||||
|
....................TTTTTTTTTTT
|
||||||
|
</code></pre>
|
||||||
|
<p>Another one is <code>9,0</code>:</p>
|
||||||
|
<pre><code>S........#.....................
|
||||||
|
.................#.............
|
||||||
|
...............................
|
||||||
|
........................#......
|
||||||
|
...............................
|
||||||
|
....................TTTTTTTTTTT
|
||||||
|
....................TTTTTTTTTT#
|
||||||
|
....................TTTTTTTTTTT
|
||||||
|
....................TTTTTTTTTTT
|
||||||
|
....................TTTTTTTTTTT
|
||||||
|
....................TTTTTTTTTTT
|
||||||
|
</code></pre>
|
||||||
|
<p>One initial velocity that <em>doesn't</em> cause the probe to be within the target area after any step is <code>17,-4</code>:</p>
|
||||||
|
<pre><code>S..............................................................
|
||||||
|
...............................................................
|
||||||
|
...............................................................
|
||||||
|
...............................................................
|
||||||
|
.................#.............................................
|
||||||
|
....................TTTTTTTTTTT................................
|
||||||
|
....................TTTTTTTTTTT................................
|
||||||
|
....................TTTTTTTTTTT................................
|
||||||
|
....................TTTTTTTTTTT................................
|
||||||
|
....................TTTTTTTTTTT..#.............................
|
||||||
|
....................TTTTTTTTTTT................................
|
||||||
|
...............................................................
|
||||||
|
...............................................................
|
||||||
|
...............................................................
|
||||||
|
...............................................................
|
||||||
|
................................................#..............
|
||||||
|
...............................................................
|
||||||
|
...............................................................
|
||||||
|
...............................................................
|
||||||
|
...............................................................
|
||||||
|
...............................................................
|
||||||
|
...............................................................
|
||||||
|
..............................................................#
|
||||||
|
</code></pre>
|
||||||
|
<p>The probe appears to pass through the target area, but is never within it after any step. Instead, it continues down and to the right - only the first few steps are shown.</p>
|
||||||
|
<p>If you're going to fire a highly scientific probe out of a super cool probe launcher, you might as well do it with <em>style</em>. How high can you make the probe go while still reaching the target area?</p>
|
||||||
|
<p>In the above example, using an initial velocity of <code>6,9</code> is the best you can do, causing the probe to reach a maximum <code>y</code> position of <code><em>45</em></code>. (Any higher initial <code>y</code> velocity causes the probe to overshoot the target area entirely.)</p>
|
||||||
|
<p>Find the initial velocity that causes the probe to reach the highest <code>y</code> position and still eventually be within the target area after any step. <em>What is the highest <code>y</code> position it reaches on this trajectory?</em></p>
|
||||||
|
</article><p>Your puzzle answer was <code>6441</code>.</p><article><h2 id="part2">--- Part Two ---</h2><p>Maybe a fancy trick shot isn't the best idea; after all, you only have one probe, so you had better not miss.</p>
|
||||||
|
<p>To get the best idea of what your options are for launching the probe, you need to find <em>every initial velocity</em> that causes the probe to eventually be within the target area after any step.</p>
|
||||||
|
<p>In the above example, there are <code><em>112</em></code> different initial velocity values that meet these criteria:</p>
|
||||||
|
<pre><code>23,-10 25,-9 27,-5 29,-6 22,-6 21,-7 9,0 27,-7 24,-5
|
||||||
|
25,-7 26,-6 25,-5 6,8 11,-2 20,-5 29,-10 6,3 28,-7
|
||||||
|
8,0 30,-6 29,-8 20,-10 6,7 6,4 6,1 14,-4 21,-6
|
||||||
|
26,-10 7,-1 7,7 8,-1 21,-9 6,2 20,-7 30,-10 14,-3
|
||||||
|
20,-8 13,-2 7,3 28,-8 29,-9 15,-3 22,-5 26,-8 25,-8
|
||||||
|
25,-6 15,-4 9,-2 15,-2 12,-2 28,-9 12,-3 24,-6 23,-7
|
||||||
|
25,-10 7,8 11,-3 26,-7 7,1 23,-9 6,0 22,-10 27,-6
|
||||||
|
8,1 22,-8 13,-4 7,6 28,-6 11,-4 12,-4 26,-9 7,4
|
||||||
|
24,-10 23,-8 30,-8 7,0 9,-1 10,-1 26,-5 22,-9 6,5
|
||||||
|
7,5 23,-6 28,-10 10,-2 11,-1 20,-9 14,-2 29,-7 13,-3
|
||||||
|
23,-5 24,-8 27,-9 30,-7 28,-5 21,-10 7,9 6,6 21,-5
|
||||||
|
27,-10 7,2 30,-9 21,-8 22,-7 24,-9 20,-6 6,9 29,-5
|
||||||
|
8,-2 27,-8 30,-5 24,-7
|
||||||
|
</code></pre>
|
||||||
|
<p><em>How many distinct initial velocity values cause the probe to be within the target area after any step?</em></p>
|
||||||
|
</article><p>Your puzzle answer was <code>3186</code>.</p></div>
|
173
18/problem.html
Normal file
173
18/problem.html
Normal file
|
@ -0,0 +1,173 @@
|
||||||
|
|
||||||
|
<!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 18 - 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 18: Snailfish ---</h2><p>You descend into the ocean trench and encounter some <a href="https://en.wikipedia.org/wiki/Snailfish" target="_blank">snailfish</a>. They say they saw the sleigh keys! They'll even tell you which direction the keys went if you help one of the smaller snailfish with his <em><span title="Snailfish math is snailfish math!">math</span> homework</em>.</p>
|
||||||
|
<p>Snailfish numbers aren't like regular numbers. Instead, every snailfish number is a <em>pair</em> - an ordered list of two elements. Each element of the pair can be either a regular number or another pair.</p>
|
||||||
|
<p>Pairs are written as <code>[x,y]</code>, where <code>x</code> and <code>y</code> are the elements within the pair. Here are some example snailfish numbers, one snailfish number per line:</p>
|
||||||
|
<pre><code>[1,2]
|
||||||
|
[[1,2],3]
|
||||||
|
[9,[8,7]]
|
||||||
|
[[1,9],[8,5]]
|
||||||
|
[[[[1,2],[3,4]],[[5,6],[7,8]]],9]
|
||||||
|
[[[9,[3,8]],[[0,9],6]],[[[3,7],[4,9]],3]]
|
||||||
|
[[[[1,3],[5,3]],[[1,3],[8,7]]],[[[4,9],[6,9]],[[8,2],[7,3]]]]
|
||||||
|
</code></pre>
|
||||||
|
<p>This snailfish homework is about <em>addition</em>. To add two snailfish numbers, form a pair from the left and right parameters of the addition operator. For example, <code>[1,2]</code> + <code>[[3,4],5]</code> becomes <code>[[1,2],[[3,4],5]]</code>.</p>
|
||||||
|
<p>There's only one problem: <em>snailfish numbers must always be reduced</em>, and the process of adding two snailfish numbers can result in snailfish numbers that need to be reduced.</p>
|
||||||
|
<p>To <em>reduce a snailfish number</em>, you must repeatedly do the first action in this list that applies to the snailfish number:</p>
|
||||||
|
<ul>
|
||||||
|
<li>If any pair is <em>nested inside four pairs</em>, the leftmost such pair <em>explodes</em>.</li>
|
||||||
|
<li>If any regular number is <em>10 or greater</em>, the leftmost such regular number <em>splits</em>.</li>
|
||||||
|
</ul>
|
||||||
|
<p>Once no action in the above list applies, the snailfish number is reduced.</p>
|
||||||
|
<p>During reduction, at most one action applies, after which the process returns to the top of the list of actions. For example, if <em>split</em> produces a pair that meets the <em>explode</em> criteria, that pair <em>explodes</em> before other <em>splits</em> occur.</p>
|
||||||
|
<p>To <em>explode</em> a pair, the pair's left value is added to the first regular number to the left of the exploding pair (if any), and the pair's right value is added to the first regular number to the right of the exploding pair (if any). Exploding pairs will always consist of two regular numbers. Then, the entire exploding pair is replaced with the regular number <code>0</code>.</p>
|
||||||
|
<p>Here are some examples of a single explode action:</p>
|
||||||
|
<ul>
|
||||||
|
<li><code>[[[[<em>[9,8]</em>,1],2],3],4]</code> becomes <code>[[[[<em>0</em>,<em>9</em>],2],3],4]</code> (the <code>9</code> has no regular number to its left, so it is not added to any regular number).</li>
|
||||||
|
<li><code>[7,[6,[5,[4,<em>[3,2]</em>]]]]</code> becomes <code>[7,[6,[5,[<em>7</em>,<em>0</em>]]]]</code> (the <code>2</code> has no regular number to its right, and so it is not added to any regular number).</li>
|
||||||
|
<li><code>[[6,[5,[4,<em>[3,2]</em>]]],1]</code> becomes <code>[[6,[5,[<em>7</em>,<em>0</em>]]],<em>3</em>]</code>.</li>
|
||||||
|
<li><code>[[3,[2,[1,<em>[7,3]</em>]]],[6,[5,[4,[3,2]]]]]</code> becomes <code>[[3,[2,[<em>8</em>,<em>0</em>]]],[<em>9</em>,[5,[4,[3,2]]]]]</code> (the pair <code>[3,2]</code> is unaffected because the pair <code>[7,3]</code> is further to the left; <code>[3,2]</code> would explode on the next action).</li>
|
||||||
|
<li><code>[[3,[2,[8,0]]],[9,[5,[4,<em>[3,2]</em>]]]]</code> becomes <code>[[3,[2,[8,0]]],[9,[5,[<em>7</em>,<em>0</em>]]]]</code>.</li>
|
||||||
|
</ul>
|
||||||
|
<p>To <em>split</em> a regular number, replace it with a pair; the left element of the pair should be the regular number divided by two and rounded <em>down</em>, while the right element of the pair should be the regular number divided by two and rounded <em>up</em>. For example, <code>10</code> becomes <code>[5,5]</code>, <code>11</code> becomes <code>[5,6]</code>, <code>12</code> becomes <code>[6,6]</code>, and so on.</p>
|
||||||
|
<p>Here is the process of finding the reduced result of <code>[[[[4,3],4],4],[7,[[8,4],9]]]</code> + <code>[1,1]</code>:</p>
|
||||||
|
<pre><code>after addition: [[[[<em>[4,3]</em>,4],4],[7,[[8,4],9]]],[1,1]]
|
||||||
|
after explode: [[[[0,7],4],[7,[<em>[8,4]</em>,9]]],[1,1]]
|
||||||
|
after explode: [[[[0,7],4],[<em>15</em>,[0,13]]],[1,1]]
|
||||||
|
after split: [[[[0,7],4],[[7,8],[0,<em>13</em>]]],[1,1]]
|
||||||
|
after split: [[[[0,7],4],[[7,8],[0,<em>[6,7]</em>]]],[1,1]]
|
||||||
|
after explode: [[[[0,7],4],[[7,8],[6,0]]],[8,1]]
|
||||||
|
</code></pre>
|
||||||
|
<p>Once no reduce actions apply, the snailfish number that remains is the actual result of the addition operation: <code>[[[[0,7],4],[[7,8],[6,0]]],[8,1]]</code>.</p>
|
||||||
|
<p>The homework assignment involves adding up a <em>list of snailfish numbers</em> (your puzzle input). The snailfish numbers are each listed on a separate line. Add the first snailfish number and the second, then add that result and the third, then add that result and the fourth, and so on until all numbers in the list have been used once.</p>
|
||||||
|
<p>For example, the final sum of this list is <code>[[[[1,1],[2,2]],[3,3]],[4,4]]</code>:</p>
|
||||||
|
<pre><code>[1,1]
|
||||||
|
[2,2]
|
||||||
|
[3,3]
|
||||||
|
[4,4]
|
||||||
|
</code></pre>
|
||||||
|
<p>The final sum of this list is <code>[[[[3,0],[5,3]],[4,4]],[5,5]]</code>:</p>
|
||||||
|
<pre><code>[1,1]
|
||||||
|
[2,2]
|
||||||
|
[3,3]
|
||||||
|
[4,4]
|
||||||
|
[5,5]
|
||||||
|
</code></pre>
|
||||||
|
<p>The final sum of this list is <code>[[[[5,0],[7,4]],[5,5]],[6,6]]</code>:</p>
|
||||||
|
<pre><code>[1,1]
|
||||||
|
[2,2]
|
||||||
|
[3,3]
|
||||||
|
[4,4]
|
||||||
|
[5,5]
|
||||||
|
[6,6]
|
||||||
|
</code></pre>
|
||||||
|
<p>Here's a slightly larger example:</p>
|
||||||
|
<pre><code>[[[0,[4,5]],[0,0]],[[[4,5],[2,6]],[9,5]]]
|
||||||
|
[7,[[[3,7],[4,3]],[[6,3],[8,8]]]]
|
||||||
|
[[2,[[0,8],[3,4]]],[[[6,7],1],[7,[1,6]]]]
|
||||||
|
[[[[2,4],7],[6,[0,5]]],[[[6,8],[2,8]],[[2,1],[4,5]]]]
|
||||||
|
[7,[5,[[3,8],[1,4]]]]
|
||||||
|
[[2,[2,2]],[8,[8,1]]]
|
||||||
|
[2,9]
|
||||||
|
[1,[[[9,3],9],[[9,0],[0,7]]]]
|
||||||
|
[[[5,[7,4]],7],1]
|
||||||
|
[[[[4,2],2],6],[8,7]]
|
||||||
|
</code></pre>
|
||||||
|
<p>The final sum <code>[[[[8,7],[7,7]],[[8,6],[7,7]]],[[[0,7],[6,6]],[8,7]]]</code> is found after adding up the above snailfish numbers:</p>
|
||||||
|
<pre><code> [[[0,[4,5]],[0,0]],[[[4,5],[2,6]],[9,5]]]
|
||||||
|
+ [7,[[[3,7],[4,3]],[[6,3],[8,8]]]]
|
||||||
|
= [[[[4,0],[5,4]],[[7,7],[6,0]]],[[8,[7,7]],[[7,9],[5,0]]]]
|
||||||
|
|
||||||
|
[[[[4,0],[5,4]],[[7,7],[6,0]]],[[8,[7,7]],[[7,9],[5,0]]]]
|
||||||
|
+ [[2,[[0,8],[3,4]]],[[[6,7],1],[7,[1,6]]]]
|
||||||
|
= [[[[6,7],[6,7]],[[7,7],[0,7]]],[[[8,7],[7,7]],[[8,8],[8,0]]]]
|
||||||
|
|
||||||
|
[[[[6,7],[6,7]],[[7,7],[0,7]]],[[[8,7],[7,7]],[[8,8],[8,0]]]]
|
||||||
|
+ [[[[2,4],7],[6,[0,5]]],[[[6,8],[2,8]],[[2,1],[4,5]]]]
|
||||||
|
= [[[[7,0],[7,7]],[[7,7],[7,8]]],[[[7,7],[8,8]],[[7,7],[8,7]]]]
|
||||||
|
|
||||||
|
[[[[7,0],[7,7]],[[7,7],[7,8]]],[[[7,7],[8,8]],[[7,7],[8,7]]]]
|
||||||
|
+ [7,[5,[[3,8],[1,4]]]]
|
||||||
|
= [[[[7,7],[7,8]],[[9,5],[8,7]]],[[[6,8],[0,8]],[[9,9],[9,0]]]]
|
||||||
|
|
||||||
|
[[[[7,7],[7,8]],[[9,5],[8,7]]],[[[6,8],[0,8]],[[9,9],[9,0]]]]
|
||||||
|
+ [[2,[2,2]],[8,[8,1]]]
|
||||||
|
= [[[[6,6],[6,6]],[[6,0],[6,7]]],[[[7,7],[8,9]],[8,[8,1]]]]
|
||||||
|
|
||||||
|
[[[[6,6],[6,6]],[[6,0],[6,7]]],[[[7,7],[8,9]],[8,[8,1]]]]
|
||||||
|
+ [2,9]
|
||||||
|
= [[[[6,6],[7,7]],[[0,7],[7,7]]],[[[5,5],[5,6]],9]]
|
||||||
|
|
||||||
|
[[[[6,6],[7,7]],[[0,7],[7,7]]],[[[5,5],[5,6]],9]]
|
||||||
|
+ [1,[[[9,3],9],[[9,0],[0,7]]]]
|
||||||
|
= [[[[7,8],[6,7]],[[6,8],[0,8]]],[[[7,7],[5,0]],[[5,5],[5,6]]]]
|
||||||
|
|
||||||
|
[[[[7,8],[6,7]],[[6,8],[0,8]]],[[[7,7],[5,0]],[[5,5],[5,6]]]]
|
||||||
|
+ [[[5,[7,4]],7],1]
|
||||||
|
= [[[[7,7],[7,7]],[[8,7],[8,7]]],[[[7,0],[7,7]],9]]
|
||||||
|
|
||||||
|
[[[[7,7],[7,7]],[[8,7],[8,7]]],[[[7,0],[7,7]],9]]
|
||||||
|
+ [[[[4,2],2],6],[8,7]]
|
||||||
|
= [[[[8,7],[7,7]],[[8,6],[7,7]]],[[[0,7],[6,6]],[8,7]]]
|
||||||
|
</code></pre>
|
||||||
|
<p>To check whether it's the right answer, the snailfish teacher only checks the <em>magnitude</em> of the final sum. The magnitude of a pair is 3 times the magnitude of its left element plus 2 times the magnitude of its right element. The magnitude of a regular number is just that number.</p>
|
||||||
|
<p>For example, the magnitude of <code>[9,1]</code> is <code>3*9 + 2*1 = <em>29</em></code>; the magnitude of <code>[1,9]</code> is <code>3*1 + 2*9 = <em>21</em></code>. Magnitude calculations are recursive: the magnitude of <code>[[9,1],[1,9]]</code> is <code>3*29 + 2*21 = <em>129</em></code>.</p>
|
||||||
|
<p>Here are a few more magnitude examples:</p>
|
||||||
|
<ul>
|
||||||
|
<li><code>[[1,2],[[3,4],5]]</code> becomes <code><em>143</em></code>.</li>
|
||||||
|
<li><code>[[[[0,7],4],[[7,8],[6,0]]],[8,1]]</code> becomes <code><em>1384</em></code>.</li>
|
||||||
|
<li><code>[[[[1,1],[2,2]],[3,3]],[4,4]]</code> becomes <code><em>445</em></code>.</li>
|
||||||
|
<li><code>[[[[3,0],[5,3]],[4,4]],[5,5]]</code> becomes <code><em>791</em></code>.</li>
|
||||||
|
<li><code>[[[[5,0],[7,4]],[5,5]],[6,6]]</code> becomes <code><em>1137</em></code>.</li>
|
||||||
|
<li><code>[[[[8,7],[7,7]],[[8,6],[7,7]]],[[[0,7],[6,6]],[8,7]]]</code> becomes <code><em>3488</em></code>.</li>
|
||||||
|
</ul>
|
||||||
|
<p>So, given this example homework assignment:</p>
|
||||||
|
<pre><code>[[[0,[5,8]],[[1,7],[9,6]]],[[4,[1,2]],[[1,4],2]]]
|
||||||
|
[[[5,[2,8]],4],[5,[[9,9],0]]]
|
||||||
|
[6,[[[6,2],[5,6]],[[7,6],[4,7]]]]
|
||||||
|
[[[6,[0,7]],[0,9]],[4,[9,[9,0]]]]
|
||||||
|
[[[7,[6,4]],[3,[1,3]]],[[[5,5],1],9]]
|
||||||
|
[[6,[[7,3],[3,2]]],[[[3,8],[5,7]],4]]
|
||||||
|
[[[[5,4],[7,7]],8],[[8,3],8]]
|
||||||
|
[[9,3],[[9,9],[6,[4,9]]]]
|
||||||
|
[[2,[[7,7],7]],[[5,8],[[9,3],[0,2]]]]
|
||||||
|
[[[[5,2],5],[8,[3,7]]],[[5,[7,5]],[4,4]]]
|
||||||
|
</code></pre>
|
||||||
|
<p>The final sum is:</p>
|
||||||
|
<pre><code>[[[[6,6],[7,6]],[[7,7],[7,0]]],[[[7,7],[7,7]],[[7,8],[9,9]]]]</code></pre>
|
||||||
|
<p>The magnitude of this final sum is <code><em>4140</em></code>.</p>
|
||||||
|
<p>Add up all of the snailfish numbers from the homework assignment in the order they appear. <em>What is the magnitude of the final sum?</em></p>
|
||||||
|
</article><p>Your puzzle answer was <code>4033</code>.</p><article><h2 id="part2">--- Part Two ---</h2><p>You notice a second question on the back of the homework assignment:</p>
|
||||||
|
<p>What is the largest magnitude you can get from adding only two of the snailfish numbers?</p>
|
||||||
|
<p>Note that snailfish addition is not <a href="https://en.wikipedia.org/wiki/Commutative_property" target="_blank">commutative</a> - that is, <code>x + y</code> and <code>y + x</code> can produce different results.</p>
|
||||||
|
<p>Again considering the last example homework assignment above:</p>
|
||||||
|
<pre><code>[[[0,[5,8]],[[1,7],[9,6]]],[[4,[1,2]],[[1,4],2]]]
|
||||||
|
[[[5,[2,8]],4],[5,[[9,9],0]]]
|
||||||
|
[6,[[[6,2],[5,6]],[[7,6],[4,7]]]]
|
||||||
|
[[[6,[0,7]],[0,9]],[4,[9,[9,0]]]]
|
||||||
|
[[[7,[6,4]],[3,[1,3]]],[[[5,5],1],9]]
|
||||||
|
[[6,[[7,3],[3,2]]],[[[3,8],[5,7]],4]]
|
||||||
|
[[[[5,4],[7,7]],8],[[8,3],8]]
|
||||||
|
[[9,3],[[9,9],[6,[4,9]]]]
|
||||||
|
[[2,[[7,7],7]],[[5,8],[[9,3],[0,2]]]]
|
||||||
|
[[[[5,2],5],[8,[3,7]]],[[5,[7,5]],[4,4]]]
|
||||||
|
</code></pre>
|
||||||
|
<p>The largest magnitude of the sum of any two snailfish numbers in this list is <code><em>3993</em></code>. This is the magnitude of <code>[[2,[[7,7],7]],[[5,8],[[9,3],[0,2]]]]</code> + <code>[[[0,[5,8]],[[1,7],[9,6]]],[[4,[1,2]],[[1,4],2]]]</code>, which reduces to <code>[[[[7,8],[6,6]],[[6,0],[7,7]]],[[[7,8],[8,8]],[[7,9],[0,6]]]]</code>.</p>
|
||||||
|
<p><em>What is the largest magnitude of any sum of two different snailfish numbers from the homework assignment?</em></p>
|
||||||
|
</article><p>Your puzzle answer was <code>4864</code>.</p></div>
|
364
19/problem.html
Normal file
364
19/problem.html
Normal file
|
@ -0,0 +1,364 @@
|
||||||
|
|
||||||
|
<!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 19 - 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 19: Beacon Scanner ---</h2><p>As your <a href="https://adventofcode.com/2021/day/17">probe</a> drifted down through this area, it released an assortment of <em>beacons</em> and <em>scanners</em> into the water. It's difficult to navigate in the pitch black open waters of the ocean trench, but if you can build a map of the trench using data from the scanners, you should be able to safely reach the bottom.</p>
|
||||||
|
<p>The beacons and scanners float motionless in the water; they're designed to maintain the same position for long periods of time. Each scanner is capable of detecting all beacons in a large cube centered on the scanner; beacons that are at most 1000 units away from the scanner in each of the three axes (<code>x</code>, <code>y</code>, and <code>z</code>) have their precise position determined relative to the scanner. However, scanners cannot detect other scanners. The submarine has automatically summarized the relative positions of beacons detected by each scanner (your puzzle input).</p>
|
||||||
|
<p>For example, if a scanner is at <code>x,y,z</code> coordinates <code>500,0,-500</code> and there are beacons at <code>-500,1000,-1500</code> and <code>1501,0,-500</code>, the scanner could report that the first beacon is at <code>-1000,1000,-1000</code> (relative to the scanner) but would not detect the second beacon at all.</p>
|
||||||
|
<p>Unfortunately, while each scanner can report the positions of all detected beacons relative to itself, <em>the scanners do not know their own position</em>. You'll need to determine the positions of the beacons and scanners yourself.</p>
|
||||||
|
<p>The scanners and beacons map a single contiguous 3d region. This region can be reconstructed by finding pairs of scanners that have overlapping detection regions such that there are <em>at least 12 beacons</em> that both scanners detect within the overlap. By establishing 12 common beacons, you can precisely determine where the scanners are relative to each other, allowing you to reconstruct the beacon map one scanner at a time.</p>
|
||||||
|
<p>For a moment, consider only two dimensions. Suppose you have the following scanner reports:</p>
|
||||||
|
<pre><code>--- scanner 0 ---
|
||||||
|
0,2
|
||||||
|
4,1
|
||||||
|
3,3
|
||||||
|
|
||||||
|
--- scanner 1 ---
|
||||||
|
-1,-1
|
||||||
|
-5,0
|
||||||
|
-2,1
|
||||||
|
</code></pre>
|
||||||
|
<p>Drawing <code>x</code> increasing rightward, <code>y</code> increasing upward, scanners as <code>S</code>, and beacons as <code>B</code>, scanner <code>0</code> detects this:</p>
|
||||||
|
<pre><code>...B.
|
||||||
|
B....
|
||||||
|
....B
|
||||||
|
S....
|
||||||
|
</code></pre>
|
||||||
|
<p>Scanner <code>1</code> detects this:</p>
|
||||||
|
<pre><code>...B..
|
||||||
|
B....S
|
||||||
|
....B.
|
||||||
|
</code></pre>
|
||||||
|
<p>For this example, assume scanners only need 3 overlapping beacons. Then, the beacons visible to both scanners overlap to produce the following complete map:</p>
|
||||||
|
<pre><code>...B..
|
||||||
|
B....S
|
||||||
|
....B.
|
||||||
|
S.....
|
||||||
|
</code></pre>
|
||||||
|
<p>Unfortunately, there's a second problem: the scanners also don't know their <em>rotation or facing direction</em>. Due to magnetic alignment, each scanner is rotated some integer number of 90-degree turns around all of the <code>x</code>, <code>y</code>, and <code>z</code> axes. That is, one scanner might call a direction positive <code>x</code>, while another scanner might call that direction negative <code>y</code>. Or, two scanners might agree on which direction is positive <code>x</code>, but one scanner might be upside-down from the perspective of the other scanner. In total, each scanner could be in any of 24 different orientations: facing positive or negative <code>x</code>, <code>y</code>, or <code>z</code>, and considering any of four directions "up" from that facing.</p>
|
||||||
|
<p>For example, here is an arrangement of beacons as seen from a scanner in the same position but in different orientations:</p>
|
||||||
|
<pre><code>--- scanner 0 ---
|
||||||
|
-1,-1,1
|
||||||
|
-2,-2,2
|
||||||
|
-3,-3,3
|
||||||
|
-2,-3,1
|
||||||
|
5,6,-4
|
||||||
|
8,0,7
|
||||||
|
|
||||||
|
--- scanner 0 ---
|
||||||
|
1,-1,1
|
||||||
|
2,-2,2
|
||||||
|
3,-3,3
|
||||||
|
2,-1,3
|
||||||
|
-5,4,-6
|
||||||
|
-8,-7,0
|
||||||
|
|
||||||
|
--- scanner 0 ---
|
||||||
|
-1,-1,-1
|
||||||
|
-2,-2,-2
|
||||||
|
-3,-3,-3
|
||||||
|
-1,-3,-2
|
||||||
|
4,6,5
|
||||||
|
-7,0,8
|
||||||
|
|
||||||
|
--- scanner 0 ---
|
||||||
|
1,1,-1
|
||||||
|
2,2,-2
|
||||||
|
3,3,-3
|
||||||
|
1,3,-2
|
||||||
|
-4,-6,5
|
||||||
|
7,0,8
|
||||||
|
|
||||||
|
--- scanner 0 ---
|
||||||
|
1,1,1
|
||||||
|
2,2,2
|
||||||
|
3,3,3
|
||||||
|
3,1,2
|
||||||
|
-6,-4,-5
|
||||||
|
0,7,-8
|
||||||
|
</code></pre>
|
||||||
|
<p>By finding pairs of scanners that both see at least 12 of the same beacons, you can assemble the entire map. For example, consider the following report:</p>
|
||||||
|
<pre><code>--- scanner 0 ---
|
||||||
|
404,-588,-901
|
||||||
|
528,-643,409
|
||||||
|
-838,591,734
|
||||||
|
390,-675,-793
|
||||||
|
-537,-823,-458
|
||||||
|
-485,-357,347
|
||||||
|
-345,-311,381
|
||||||
|
-661,-816,-575
|
||||||
|
-876,649,763
|
||||||
|
-618,-824,-621
|
||||||
|
553,345,-567
|
||||||
|
474,580,667
|
||||||
|
-447,-329,318
|
||||||
|
-584,868,-557
|
||||||
|
544,-627,-890
|
||||||
|
564,392,-477
|
||||||
|
455,729,728
|
||||||
|
-892,524,684
|
||||||
|
-689,845,-530
|
||||||
|
423,-701,434
|
||||||
|
7,-33,-71
|
||||||
|
630,319,-379
|
||||||
|
443,580,662
|
||||||
|
-789,900,-551
|
||||||
|
459,-707,401
|
||||||
|
|
||||||
|
--- scanner 1 ---
|
||||||
|
686,422,578
|
||||||
|
605,423,415
|
||||||
|
515,917,-361
|
||||||
|
-336,658,858
|
||||||
|
95,138,22
|
||||||
|
-476,619,847
|
||||||
|
-340,-569,-846
|
||||||
|
567,-361,727
|
||||||
|
-460,603,-452
|
||||||
|
669,-402,600
|
||||||
|
729,430,532
|
||||||
|
-500,-761,534
|
||||||
|
-322,571,750
|
||||||
|
-466,-666,-811
|
||||||
|
-429,-592,574
|
||||||
|
-355,545,-477
|
||||||
|
703,-491,-529
|
||||||
|
-328,-685,520
|
||||||
|
413,935,-424
|
||||||
|
-391,539,-444
|
||||||
|
586,-435,557
|
||||||
|
-364,-763,-893
|
||||||
|
807,-499,-711
|
||||||
|
755,-354,-619
|
||||||
|
553,889,-390
|
||||||
|
|
||||||
|
--- scanner 2 ---
|
||||||
|
649,640,665
|
||||||
|
682,-795,504
|
||||||
|
-784,533,-524
|
||||||
|
-644,584,-595
|
||||||
|
-588,-843,648
|
||||||
|
-30,6,44
|
||||||
|
-674,560,763
|
||||||
|
500,723,-460
|
||||||
|
609,671,-379
|
||||||
|
-555,-800,653
|
||||||
|
-675,-892,-343
|
||||||
|
697,-426,-610
|
||||||
|
578,704,681
|
||||||
|
493,664,-388
|
||||||
|
-671,-858,530
|
||||||
|
-667,343,800
|
||||||
|
571,-461,-707
|
||||||
|
-138,-166,112
|
||||||
|
-889,563,-600
|
||||||
|
646,-828,498
|
||||||
|
640,759,510
|
||||||
|
-630,509,768
|
||||||
|
-681,-892,-333
|
||||||
|
673,-379,-804
|
||||||
|
-742,-814,-386
|
||||||
|
577,-820,562
|
||||||
|
|
||||||
|
--- scanner 3 ---
|
||||||
|
-589,542,597
|
||||||
|
605,-692,669
|
||||||
|
-500,565,-823
|
||||||
|
-660,373,557
|
||||||
|
-458,-679,-417
|
||||||
|
-488,449,543
|
||||||
|
-626,468,-788
|
||||||
|
338,-750,-386
|
||||||
|
528,-832,-391
|
||||||
|
562,-778,733
|
||||||
|
-938,-730,414
|
||||||
|
543,643,-506
|
||||||
|
-524,371,-870
|
||||||
|
407,773,750
|
||||||
|
-104,29,83
|
||||||
|
378,-903,-323
|
||||||
|
-778,-728,485
|
||||||
|
426,699,580
|
||||||
|
-438,-605,-362
|
||||||
|
-469,-447,-387
|
||||||
|
509,732,623
|
||||||
|
647,635,-688
|
||||||
|
-868,-804,481
|
||||||
|
614,-800,639
|
||||||
|
595,780,-596
|
||||||
|
|
||||||
|
--- scanner 4 ---
|
||||||
|
727,592,562
|
||||||
|
-293,-554,779
|
||||||
|
441,611,-461
|
||||||
|
-714,465,-776
|
||||||
|
-743,427,-804
|
||||||
|
-660,-479,-426
|
||||||
|
832,-632,460
|
||||||
|
927,-485,-438
|
||||||
|
408,393,-506
|
||||||
|
466,436,-512
|
||||||
|
110,16,151
|
||||||
|
-258,-428,682
|
||||||
|
-393,719,612
|
||||||
|
-211,-452,876
|
||||||
|
808,-476,-593
|
||||||
|
-575,615,604
|
||||||
|
-485,667,467
|
||||||
|
-680,325,-822
|
||||||
|
-627,-443,-432
|
||||||
|
872,-547,-609
|
||||||
|
833,512,582
|
||||||
|
807,604,487
|
||||||
|
839,-516,451
|
||||||
|
891,-625,532
|
||||||
|
-652,-548,-490
|
||||||
|
30,-46,-14
|
||||||
|
</code></pre>
|
||||||
|
<p>Because all coordinates are relative, in this example, all "absolute" positions will be expressed relative to scanner <code>0</code> (using the orientation of scanner <code>0</code> and as if scanner <code>0</code> is at coordinates <code>0,0,0</code>).</p>
|
||||||
|
<p>Scanners <code>0</code> and <code>1</code> have overlapping detection cubes; the 12 beacons they both detect (relative to scanner <code>0</code>) are at the following coordinates:</p>
|
||||||
|
<pre><code>-618,-824,-621
|
||||||
|
-537,-823,-458
|
||||||
|
-447,-329,318
|
||||||
|
404,-588,-901
|
||||||
|
544,-627,-890
|
||||||
|
528,-643,409
|
||||||
|
-661,-816,-575
|
||||||
|
390,-675,-793
|
||||||
|
423,-701,434
|
||||||
|
-345,-311,381
|
||||||
|
459,-707,401
|
||||||
|
-485,-357,347
|
||||||
|
</code></pre>
|
||||||
|
<p>These same 12 beacons (in the same order) but from the perspective of scanner <code>1</code> are:</p>
|
||||||
|
<pre><code>686,422,578
|
||||||
|
605,423,415
|
||||||
|
515,917,-361
|
||||||
|
-336,658,858
|
||||||
|
-476,619,847
|
||||||
|
-460,603,-452
|
||||||
|
729,430,532
|
||||||
|
-322,571,750
|
||||||
|
-355,545,-477
|
||||||
|
413,935,-424
|
||||||
|
-391,539,-444
|
||||||
|
553,889,-390
|
||||||
|
</code></pre>
|
||||||
|
<p>Because of this, scanner <code>1</code> must be at <code>68,-1246,-43</code> (relative to scanner <code>0</code>).</p>
|
||||||
|
<p>Scanner <code>4</code> overlaps with scanner <code>1</code>; the 12 beacons they both detect (relative to scanner <code>0</code>) are:</p>
|
||||||
|
<pre><code>459,-707,401
|
||||||
|
-739,-1745,668
|
||||||
|
-485,-357,347
|
||||||
|
432,-2009,850
|
||||||
|
528,-643,409
|
||||||
|
423,-701,434
|
||||||
|
-345,-311,381
|
||||||
|
408,-1815,803
|
||||||
|
534,-1912,768
|
||||||
|
-687,-1600,576
|
||||||
|
-447,-329,318
|
||||||
|
-635,-1737,486
|
||||||
|
</code></pre>
|
||||||
|
<p>So, scanner <code>4</code> is at <code>-20,-1133,1061</code> (relative to scanner <code>0</code>).</p>
|
||||||
|
<p>Following this process, scanner <code>2</code> must be at <code>1105,-1205,1229</code> (relative to scanner <code>0</code>) and scanner <code>3</code> must be at <code>-92,-2380,-20</code> (relative to scanner <code>0</code>).</p>
|
||||||
|
<p>The full list of beacons (relative to scanner <code>0</code>) is:</p>
|
||||||
|
<pre><code>-892,524,684
|
||||||
|
-876,649,763
|
||||||
|
-838,591,734
|
||||||
|
-789,900,-551
|
||||||
|
-739,-1745,668
|
||||||
|
-706,-3180,-659
|
||||||
|
-697,-3072,-689
|
||||||
|
-689,845,-530
|
||||||
|
-687,-1600,576
|
||||||
|
-661,-816,-575
|
||||||
|
-654,-3158,-753
|
||||||
|
-635,-1737,486
|
||||||
|
-631,-672,1502
|
||||||
|
-624,-1620,1868
|
||||||
|
-620,-3212,371
|
||||||
|
-618,-824,-621
|
||||||
|
-612,-1695,1788
|
||||||
|
-601,-1648,-643
|
||||||
|
-584,868,-557
|
||||||
|
-537,-823,-458
|
||||||
|
-532,-1715,1894
|
||||||
|
-518,-1681,-600
|
||||||
|
-499,-1607,-770
|
||||||
|
-485,-357,347
|
||||||
|
-470,-3283,303
|
||||||
|
-456,-621,1527
|
||||||
|
-447,-329,318
|
||||||
|
-430,-3130,366
|
||||||
|
-413,-627,1469
|
||||||
|
-345,-311,381
|
||||||
|
-36,-1284,1171
|
||||||
|
-27,-1108,-65
|
||||||
|
7,-33,-71
|
||||||
|
12,-2351,-103
|
||||||
|
26,-1119,1091
|
||||||
|
346,-2985,342
|
||||||
|
366,-3059,397
|
||||||
|
377,-2827,367
|
||||||
|
390,-675,-793
|
||||||
|
396,-1931,-563
|
||||||
|
404,-588,-901
|
||||||
|
408,-1815,803
|
||||||
|
423,-701,434
|
||||||
|
432,-2009,850
|
||||||
|
443,580,662
|
||||||
|
455,729,728
|
||||||
|
456,-540,1869
|
||||||
|
459,-707,401
|
||||||
|
465,-695,1988
|
||||||
|
474,580,667
|
||||||
|
496,-1584,1900
|
||||||
|
497,-1838,-617
|
||||||
|
527,-524,1933
|
||||||
|
528,-643,409
|
||||||
|
534,-1912,768
|
||||||
|
544,-627,-890
|
||||||
|
553,345,-567
|
||||||
|
564,392,-477
|
||||||
|
568,-2007,-577
|
||||||
|
605,-1665,1952
|
||||||
|
612,-1593,1893
|
||||||
|
630,319,-379
|
||||||
|
686,-3108,-505
|
||||||
|
776,-3184,-501
|
||||||
|
846,-3110,-434
|
||||||
|
1135,-1161,1235
|
||||||
|
1243,-1093,1063
|
||||||
|
1660,-552,429
|
||||||
|
1693,-557,386
|
||||||
|
1735,-437,1738
|
||||||
|
1749,-1800,1813
|
||||||
|
1772,-405,1572
|
||||||
|
1776,-675,371
|
||||||
|
1779,-442,1789
|
||||||
|
1780,-1548,337
|
||||||
|
1786,-1538,337
|
||||||
|
1847,-1591,415
|
||||||
|
1889,-1729,1762
|
||||||
|
1994,-1805,1792
|
||||||
|
</code></pre>
|
||||||
|
<p>In total, there are <code><em>79</em></code> beacons.</p>
|
||||||
|
<p>Assemble the full map of beacons. <em>How many beacons are there?</em></p>
|
||||||
|
</article><p>Your puzzle answer was <code>396</code>.</p><article><h2 id="part2">--- Part Two ---</h2><p>Sometimes, it's a good idea to appreciate just how <span title="The deepest parts of the ocean are about as deep as the altitude of a normal commercial aircraft, roughly 11 kilometers or 36000 feet.">big</span> the ocean is. Using the <a href="https://en.wikipedia.org/wiki/Taxicab_geometry" target="_blank">Manhattan distance</a>, how far apart do the scanners get?</p>
|
||||||
|
<p>In the above example, scanners <code>2</code> (<code>1105,-1205,1229</code>) and <code>3</code> (<code>-92,-2380,-20</code>) are the largest Manhattan distance apart. In total, they are <code>1197 + 1175 + 1249 = <em>3621</em></code> units apart.</p>
|
||||||
|
<p><em>What is the largest Manhattan distance between any two scanners?</em></p>
|
||||||
|
</article><p>Your puzzle answer was <code>11828</code>.</p></div>
|
110
20/problem.html
Normal file
110
20/problem.html
Normal file
|
@ -0,0 +1,110 @@
|
||||||
|
|
||||||
|
<!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 20 - 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 20: Trench Map ---</h2><p>With the scanners fully deployed, you turn their attention to mapping the floor of the ocean trench.</p>
|
||||||
|
<p>When you get back the image from the scanners, it seems to just be random noise. Perhaps you can combine an image enhancement algorithm and the input image (your puzzle input) to clean it up a little.</p>
|
||||||
|
<p>For example:</p>
|
||||||
|
<pre><code>..#.#..#####.#.#.#.###.##.....###.##.#..###.####..#####..#....#..#..##..##
|
||||||
|
#..######.###...####..#..#####..##..#.#####...##.#.#..#.##..#.#......#.###
|
||||||
|
.######.###.####...#.##.##..#..#..#####.....#.#....###..#.##......#.....#.
|
||||||
|
.#..#..##..#...##.######.####.####.#.#...#.......#..#.#.#...####.##.#.....
|
||||||
|
.#..#...##.#.##..#...##.#.##..###.#......#.#.......#.#.#.####.###.##...#..
|
||||||
|
...####.#..#..#.##.#....##..#.####....##...##..#...#......#.#.......#.....
|
||||||
|
..##..####..#...#.#.#...##..#.#..###..#####........#..####......#..#
|
||||||
|
|
||||||
|
#..#.
|
||||||
|
#....
|
||||||
|
##..#
|
||||||
|
..#..
|
||||||
|
..###
|
||||||
|
</code></pre>
|
||||||
|
<p>The first section is the <em>image enhancement algorithm</em>. It is normally given on a single line, but it has been wrapped to multiple lines in this example for legibility. The second section is the <em>input image</em>, a two-dimensional grid of <em>light pixels</em> (<code>#</code>) and <em>dark pixels</em> (<code>.</code>).</p>
|
||||||
|
<p>The image enhancement algorithm describes how to enhance an image by <em>simultaneously</em> converting all pixels in the input image into an output image. Each pixel of the output image is determined by looking at a 3x3 square of pixels centered on the corresponding input image pixel. So, to determine the value of the pixel at (5,10) in the output image, nine pixels from the input image need to be considered: (4,9), (4,10), (4,11), (5,9), (5,10), (5,11), (6,9), (6,10), and (6,11). These nine input pixels are combined into a single binary number that is used as an index in the <em>image enhancement algorithm</em> string.</p>
|
||||||
|
<p>For example, to determine the output pixel that corresponds to the very middle pixel of the input image, the nine pixels marked by <code>[...]</code> would need to be considered:</p>
|
||||||
|
<pre><code># . . # .
|
||||||
|
#[. . .].
|
||||||
|
#[# . .]#
|
||||||
|
.[. # .].
|
||||||
|
. . # # #
|
||||||
|
</code></pre>
|
||||||
|
<p>Starting from the top-left and reading across each row, these pixels are <code>...</code>, then <code>#..</code>, then <code>.#.</code>; combining these forms <code>...#...#.</code>. By turning dark pixels (<code>.</code>) into <code>0</code> and light pixels (<code>#</code>) into <code>1</code>, the binary number <code>000100010</code> can be formed, which is <code>34</code> in decimal.</p>
|
||||||
|
<p>The image enhancement algorithm string is exactly 512 characters long, enough to match every possible 9-bit binary number. The first few characters of the string (numbered starting from zero) are as follows:</p>
|
||||||
|
<pre><code>0 10 20 30 <em>34</em> 40 50 60 70
|
||||||
|
| | | | <em>|</em> | | | |
|
||||||
|
..#.#..#####.#.#.#.###.##.....###.<em>#</em>#.#..###.####..#####..#....#..#..##..##
|
||||||
|
</code></pre>
|
||||||
|
<p>In the middle of this first group of characters, the character at index 34 can be found: <code>#</code>. So, the output pixel in the center of the output image should be <code>#</code>, a <em>light pixel</em>.</p>
|
||||||
|
<p>This process can then be repeated to calculate every pixel of the output image.</p>
|
||||||
|
<p>Through advances in imaging technology, the images being operated on here are <em>infinite</em> in size. <em>Every</em> pixel of the infinite output image needs to be calculated exactly based on the relevant pixels of the input image. The small input image you have is only a small region of the actual infinite input image; the rest of the input image consists of dark pixels (<code>.</code>). For the purposes of the example, to save on space, only a portion of the infinite-sized input and output images will be shown.</p>
|
||||||
|
<p>The starting input image, therefore, looks something like this, with more dark pixels (<code>.</code>) extending forever in every direction not shown here:</p>
|
||||||
|
<pre><code>...............
|
||||||
|
...............
|
||||||
|
...............
|
||||||
|
...............
|
||||||
|
...............
|
||||||
|
.....#..#......
|
||||||
|
.....#.........
|
||||||
|
.....##..#.....
|
||||||
|
.......#.......
|
||||||
|
.......###.....
|
||||||
|
...............
|
||||||
|
...............
|
||||||
|
...............
|
||||||
|
...............
|
||||||
|
...............
|
||||||
|
</code></pre>
|
||||||
|
<p>By applying the image enhancement algorithm to every pixel simultaneously, the following output image can be obtained:</p>
|
||||||
|
<pre><code>...............
|
||||||
|
...............
|
||||||
|
...............
|
||||||
|
...............
|
||||||
|
.....##.##.....
|
||||||
|
....#..#.#.....
|
||||||
|
....##.#..#....
|
||||||
|
....####..#....
|
||||||
|
.....#..##.....
|
||||||
|
......##..#....
|
||||||
|
.......#.#.....
|
||||||
|
...............
|
||||||
|
...............
|
||||||
|
...............
|
||||||
|
...............
|
||||||
|
</code></pre>
|
||||||
|
<p>Through further advances in imaging technology, the above output image can also be used as an input image! This allows it to be enhanced <em>a second time</em>:</p>
|
||||||
|
<pre><code>...............
|
||||||
|
...............
|
||||||
|
...............
|
||||||
|
..........#....
|
||||||
|
....#..#.#.....
|
||||||
|
...#.#...###...
|
||||||
|
...#...##.#....
|
||||||
|
...#.....#.#...
|
||||||
|
....#.#####....
|
||||||
|
.....#.#####...
|
||||||
|
......##.##....
|
||||||
|
.......###.....
|
||||||
|
...............
|
||||||
|
...............
|
||||||
|
...............
|
||||||
|
</code></pre>
|
||||||
|
<p>Truly incredible - now the small details are really starting to come through. After enhancing the original input image twice, <code><em>35</em></code> pixels are lit.</p>
|
||||||
|
<p>Start with the original input image and apply the image enhancement algorithm twice, being careful to account for the infinite size of the images. <em>How many pixels are lit in the resulting image?</em></p>
|
||||||
|
</article><p>Your puzzle answer was <code>4873</code>.</p><article><h2 id="part2">--- Part Two ---</h2><p>You still can't quite make out the details in the image. Maybe you just didn't <a href="https://en.wikipedia.org/wiki/Kernel_(image_processing)" target="_blank">enhance</a> it <span title="Yeah, that's definitely the problem.">enough</span>.</p>
|
||||||
|
<p>If you enhance the starting input image in the above example a total of <em>50</em> times, <code><em>3351</em></code> pixels are lit in the final output image.</p>
|
||||||
|
<p>Start again with the original input image and apply the image enhancement algorithm 50 times. <em>How many pixels are lit in the resulting image?</em></p>
|
||||||
|
</article><p>Your puzzle answer was <code>16394</code>.</p></div>
|
Loading…
Reference in a new issue