Done day 24
[advent-of-code-22.git] / problems / day24.html
1 <!DOCTYPE html>
2 <html lang="en-us">
3 <head>
4 <meta charset="utf-8"/>
5 <title>Day 24 - Advent of Code 2022</title>
6 <!--[if lt IE 9]><script src="/static/html5.js"></script><![endif]-->
7 <link href='//fonts.googleapis.com/css?family=Source+Code+Pro:300&subset=latin,latin-ext' rel='stylesheet' type='text/css'/>
8 <link rel="stylesheet" type="text/css" href="/static/style.css?30"/>
9 <link rel="stylesheet alternate" type="text/css" href="/static/highcontrast.css?0" title="High Contrast"/>
10 <link rel="shortcut icon" href="/favicon.png"/>
11 <script>window.addEventListener('click', function(e,s,r){if(e.target.nodeName==='CODE'&&e.detail===3){s=window.getSelection();s.removeAllRanges();r=document.createRange();r.selectNodeContents(e.target);s.addRange(r);}});</script>
12 </head><!--
13
14
15
16
17 Oh, hello! Funny seeing you here.
18
19 I appreciate your enthusiasm, but you aren't going to find much down here.
20 There certainly aren't clues to any of the puzzles. The best surprises don't
21 even appear in the source until you unlock them for real.
22
23 Please be careful with automated requests; I'm not a massive company, and I can
24 only take so much traffic. Please be considerate so that everyone gets to play.
25
26 If you're curious about how Advent of Code works, it's running on some custom
27 Perl code. Other than a few integrations (auth, analytics, social media), I
28 built the whole thing myself, including the design, animations, prose, and all
29 of the puzzles.
30
31 The puzzles are most of the work; preparing a new calendar and a new set of
32 puzzles each year takes all of my free time for 4-5 months. A lot of effort
33 went into building this thing - I hope you're enjoying playing it as much as I
34 enjoyed making it for you!
35
36 If you'd like to hang out, I'm @ericwastl on Twitter.
37
38 - Eric Wastl
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89 -->
90 <body>
91 <header><div><h1 class="title-global"><a href="/">Advent of Code</a></h1><nav><ul><li><a href="/2022/about">[About]</a></li><li><a href="/2022/events">[Events]</a></li><li><a href="https://teespring.com/stores/advent-of-code" target="_blank">[Shop]</a></li><li><a href="/2022/settings">[Settings]</a></li><li><a href="/2022/auth/logout">[Log Out]</a></li></ul></nav><div class="user">Neil Smith <a href="/2022/support" class="supporter-badge" title="Advent of Code Supporter">(AoC++)</a> <span class="star-count">48*</span></div></div><div><h1 class="title-event">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="title-event-wrap">/*</span><a href="/2022">2022</a><span class="title-event-wrap">*/</span></h1><nav><ul><li><a href="/2022">[Calendar]</a></li><li><a href="/2022/support">[AoC++]</a></li><li><a href="/2022/sponsors">[Sponsors]</a></li><li><a href="/2022/leaderboard">[Leaderboard]</a></li><li><a href="/2022/stats">[Stats]</a></li></ul></nav></div></header>
92
93 <div id="sidebar">
94 <div id="sponsor"><div class="quiet">Our <a href="/2022/sponsors">sponsors</a> help make Advent of Code possible:</div><div class="sponsor"><a href="https://www.americanexpress.com/en-us/careers/career-areas/technology/" target="_blank" onclick="if(ga)ga('send','event','sponsor','sidebar',this.href);" rel="noopener">American Express</a> - Work with the latest tech and back the engineering community through open source. Find your place in tech on #TeamAmex.</div></div>
95 </div><!--/sidebar-->
96
97 <main>
98 <article class="day-desc"><h2>--- Day 24: Blizzard Basin ---</h2><p>With everything replanted for next year (and with elephants and monkeys to tend the grove), you and the Elves leave for the extraction point.</p>
99 <p>Partway up the mountain that shields the grove is a flat, open area that serves as the extraction point. It's a bit of a climb, but nothing the expedition can't handle.</p>
100 <p>At least, that would normally be true; now that the mountain is covered in snow, things have become more difficult than the Elves are used to.</p>
101 <p>As the expedition reaches a valley that must be traversed to reach the extraction site, you find that strong, turbulent winds are pushing small <em>blizzards</em> of snow and sharp ice around the valley. It's a good thing everyone packed warm clothes! To make it across safely, you'll need to find a way to avoid them.</p>
102 <p>Fortunately, it's easy to see all of this from the entrance to the valley, so you make a map of the valley and the blizzards (your puzzle input). For example:</p>
103 <pre><code>#.#####
104 #.....#
105 #&gt;....#
106 #.....#
107 #...v.#
108 #.....#
109 #####.#
110 </code></pre>
111 <p>The walls of the valley are drawn as <code>#</code>; everything else is ground. Clear ground - where there is currently no blizzard - is drawn as <code>.</code>. Otherwise, blizzards are drawn with an arrow indicating their direction of motion: up (<code>^</code>), down (<code>v</code>), left (<code>&lt;</code>), or right (<code>&gt;</code>).</p>
112 <p>The above map includes two blizzards, one moving right (<code>&gt;</code>) and one moving down (<code>v</code>). In one minute, each blizzard moves one position in the direction it is pointing:</p>
113 <pre><code>#.#####
114 #.....#
115 #.&gt;...#
116 #.....#
117 #.....#
118 #...v.#
119 #####.#
120 </code></pre>
121 <p>Due to <span title="I think, anyway. Do I look like a theoretical blizzacist?">conservation of blizzard energy</span>, as a blizzard reaches the wall of the valley, a new blizzard forms on the opposite side of the valley moving in the same direction. After another minute, the bottom downward-moving blizzard has been replaced with a new downward-moving blizzard at the top of the valley instead:</p>
122 <pre><code>#.#####
123 #...v.#
124 #..&gt;..#
125 #.....#
126 #.....#
127 #.....#
128 #####.#
129 </code></pre>
130 <p>Because blizzards are made of tiny snowflakes, they pass right through each other. After another minute, both blizzards temporarily occupy the same position, marked <code>2</code>:</p>
131 <pre><code>#.#####
132 #.....#
133 #...2.#
134 #.....#
135 #.....#
136 #.....#
137 #####.#
138 </code></pre>
139 <p>After another minute, the situation resolves itself, giving each blizzard back its personal space:</p>
140 <pre><code>#.#####
141 #.....#
142 #....&gt;#
143 #...v.#
144 #.....#
145 #.....#
146 #####.#
147 </code></pre>
148 <p>Finally, after yet another minute, the rightward-facing blizzard on the right is replaced with a new one on the left facing the same direction:</p>
149 <pre><code>#.#####
150 #.....#
151 #&gt;....#
152 #.....#
153 #...v.#
154 #.....#
155 #####.#
156 </code></pre>
157 <p>This process repeats at least as long as you are observing it, but probably forever.</p>
158 <p>Here is a more complex example:</p>
159 <pre><code>#.######
160 #&gt;&gt;.&lt;^&lt;#
161 #.&lt;..&lt;&lt;#
162 #&gt;v.&gt;&lt;&gt;#
163 #&lt;^v^^&gt;#
164 ######.#
165 </code></pre>
166 <p>Your expedition begins in the only non-wall position in the top row and needs to reach the only non-wall position in the bottom row. On each minute, you can <em>move</em> up, down, left, or right, or you can <em>wait</em> in place. You and the blizzards act <em>simultaneously</em>, and you cannot share a position with a blizzard.</p>
167 <p>In the above example, the fastest way to reach your goal requires <code><em>18</em></code> steps. Drawing the position of the expedition as <code>E</code>, one way to achieve this is:</p>
168 <pre><code>Initial state:
169 #<em>E</em>######
170 #&gt;&gt;.&lt;^&lt;#
171 #.&lt;..&lt;&lt;#
172 #&gt;v.&gt;&lt;&gt;#
173 #&lt;^v^^&gt;#
174 ######.#
175
176 Minute 1, move down:
177 #.######
178 #<em>E</em>&gt;3.&lt;.#
179 #&lt;..&lt;&lt;.#
180 #&gt;2.22.#
181 #&gt;v..^&lt;#
182 ######.#
183
184 Minute 2, move down:
185 #.######
186 #.2&gt;2..#
187 #<em>E</em>^22^&lt;#
188 #.&gt;2.^&gt;#
189 #.&gt;..&lt;.#
190 ######.#
191
192 Minute 3, wait:
193 #.######
194 #&lt;^&lt;22.#
195 #<em>E</em>2&lt;.2.#
196 #&gt;&lt;2&gt;..#
197 #..&gt;&lt;..#
198 ######.#
199
200 Minute 4, move up:
201 #.######
202 #<em>E</em>&lt;..22#
203 #&lt;&lt;.&lt;..#
204 #&lt;2.&gt;&gt;.#
205 #.^22^.#
206 ######.#
207
208 Minute 5, move right:
209 #.######
210 #2<em>E</em>v.&lt;&gt;#
211 #&lt;.&lt;..&lt;#
212 #.^&gt;^22#
213 #.2..2.#
214 ######.#
215
216 Minute 6, move right:
217 #.######
218 #&gt;2<em>E</em>&lt;.&lt;#
219 #.2v^2&lt;#
220 #&gt;..&gt;2&gt;#
221 #&lt;....&gt;#
222 ######.#
223
224 Minute 7, move down:
225 #.######
226 #.22^2.#
227 #&lt;v<em>E</em>&lt;2.#
228 #&gt;&gt;v&lt;&gt;.#
229 #&gt;....&lt;#
230 ######.#
231
232 Minute 8, move left:
233 #.######
234 #.&lt;&gt;2^.#
235 #.<em>E</em>&lt;&lt;.&lt;#
236 #.22..&gt;#
237 #.2v^2.#
238 ######.#
239
240 Minute 9, move up:
241 #.######
242 #&lt;<em>E</em>2&gt;&gt;.#
243 #.&lt;&lt;.&lt;.#
244 #&gt;2&gt;2^.#
245 #.v&gt;&lt;^.#
246 ######.#
247
248 Minute 10, move right:
249 #.######
250 #.2<em>E</em>.&gt;2#
251 #&lt;2v2^.#
252 #&lt;&gt;.&gt;2.#
253 #..&lt;&gt;..#
254 ######.#
255
256 Minute 11, wait:
257 #.######
258 #2^<em>E</em>^2&gt;#
259 #&lt;v&lt;.^&lt;#
260 #..2.&gt;2#
261 #.&lt;..&gt;.#
262 ######.#
263
264 Minute 12, move down:
265 #.######
266 #&gt;&gt;.&lt;^&lt;#
267 #.&lt;<em>E</em>.&lt;&lt;#
268 #&gt;v.&gt;&lt;&gt;#
269 #&lt;^v^^&gt;#
270 ######.#
271
272 Minute 13, move down:
273 #.######
274 #.&gt;3.&lt;.#
275 #&lt;..&lt;&lt;.#
276 #&gt;2<em>E</em>22.#
277 #&gt;v..^&lt;#
278 ######.#
279
280 Minute 14, move right:
281 #.######
282 #.2&gt;2..#
283 #.^22^&lt;#
284 #.&gt;2<em>E</em>^&gt;#
285 #.&gt;..&lt;.#
286 ######.#
287
288 Minute 15, move right:
289 #.######
290 #&lt;^&lt;22.#
291 #.2&lt;.2.#
292 #&gt;&lt;2&gt;<em>E</em>.#
293 #..&gt;&lt;..#
294 ######.#
295
296 Minute 16, move right:
297 #.######
298 #.&lt;..22#
299 #&lt;&lt;.&lt;..#
300 #&lt;2.&gt;&gt;<em>E</em>#
301 #.^22^.#
302 ######.#
303
304 Minute 17, move down:
305 #.######
306 #2.v.&lt;&gt;#
307 #&lt;.&lt;..&lt;#
308 #.^&gt;^22#
309 #.2..2<em>E</em>#
310 ######.#
311
312 Minute 18, move down:
313 #.######
314 #&gt;2.&lt;.&lt;#
315 #.2v^2&lt;#
316 #&gt;..&gt;2&gt;#
317 #&lt;....&gt;#
318 ######<em>E</em>#
319 </code></pre>
320 <p><em>What is the fewest number of minutes required to avoid the blizzards and reach the goal?</em></p>
321 </article>
322 <p>Your puzzle answer was <code>288</code>.</p><article class="day-desc"><h2 id="part2">--- Part Two ---</h2><p>As the expedition reaches the far side of the valley, one of the Elves looks especially dismayed:</p>
323 <p>He <em>forgot his snacks</em> at the entrance to the valley!</p>
324 <p>Since you're so good at dodging blizzards, the Elves humbly request that you go back for his snacks. From the same initial conditions, how quickly can you make it from the start to the goal, then back to the start, then back to the goal?</p>
325 <p>In the above example, the first trip to the goal takes <code>18</code> minutes, the trip back to the start takes <code>23</code> minutes, and the trip back to the goal again takes <code>13</code> minutes, for a total time of <code><em>54</em></code> minutes.</p>
326 <p><em>What is the fewest number of minutes required to reach the goal, go back to the start, then reach the goal again?</em></p>
327 </article>
328 <p>Your puzzle answer was <code>861</code>.</p><p class="day-success">Both parts of this puzzle are complete! They provide two gold stars: **</p>
329 <p>At this point, you should <a href="/2022">return to your Advent calendar</a> and try another puzzle.</p>
330 <p>If you still want to see it, you can <a href="24/input" target="_blank">get your puzzle input</a>.</p>
331 <p>You can also <span class="share">[Share<span class="share-content">on
332 <a href="https://twitter.com/intent/tweet?text=I%27ve+completed+%22Blizzard+Basin%22+%2D+Day+24+%2D+Advent+of+Code+2022&amp;url=https%3A%2F%2Fadventofcode%2Ecom%2F2022%2Fday%2F24&amp;related=ericwastl&amp;hashtags=AdventOfCode" target="_blank">Twitter</a>
333 <a href="javascript:void(0);" onclick="var mastodon_instance=prompt('Mastodon Instance / Server Name?'); if(typeof mastodon_instance==='string' && mastodon_instance.length){this.href='https://'+mastodon_instance+'/share?text=I%27ve+completed+%22Blizzard+Basin%22+%2D+Day+24+%2D+Advent+of+Code+2022+%23AdventOfCode+https%3A%2F%2Fadventofcode%2Ecom%2F2022%2Fday%2F24'}else{return false;}" target="_blank">Mastodon</a
334 ></span>]</span> this puzzle.</p>
335 </main>
336
337 <!-- ga -->
338 <script>
339 (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
340 (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
341 m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
342 })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
343 ga('create', 'UA-69522494-1', 'auto');
344 ga('set', 'anonymizeIp', true);
345 ga('send', 'pageview');
346 </script>
347 <!-- /ga -->
348 </body>
349 </html>