Optimised day 19
[advent-of-code-22.git] / problems / day17.html
1 <!DOCTYPE html>
2 <html lang="en-us">
3 <head>
4 <meta charset="utf-8"/>
5 <title>Day 17 - 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">34*</span></div></div><div><h1 class="title-event">&nbsp;&nbsp;&nbsp;<span class="title-event-wrap">0xffff&amp;</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://optiver.com/advent-of-code" target="_blank" onclick="if(ga)ga('send','event','sponsor','sidebar',this.href);" rel="noopener">Optiver</a> - Love solving puzzles? So do we! We&apos;re hiring engineers to code trading systems with sub-nanosecond performance. Get ready for daily challenges, continuous learning and the freedom to bring your software solutions to life</div></div>
95 </div><!--/sidebar-->
96
97 <main>
98 <article class="day-desc"><h2>--- Day 17: Pyroclastic Flow ---</h2><p>Your handheld device has located an alternative exit from the cave for you and the elephants. The ground is rumbling almost continuously now, but the strange valves bought you some time. It's definitely getting warmer in here, though.</p>
99 <p>The tunnels eventually open into a very tall, narrow chamber. Large, oddly-shaped rocks are falling into the chamber from above, presumably due to all the rumbling. If you can't work out where the rocks will fall next, you might be <span title="I am the man who arranges the blocks / that descend upon me from up above!">crushed</span>!</p>
100 <p>The five types of rocks have the following peculiar shapes, where <code>#</code> is rock and <code>.</code> is empty space:</p>
101 <pre><code>####
102
103 .#.
104 ###
105 .#.
106
107 ..#
108 ..#
109 ###
110
111 #
112 #
113 #
114 #
115
116 ##
117 ##
118 </code></pre>
119 <p>The rocks fall in the order shown above: first the <code>-</code> shape, then the <code>+</code> shape, and so on. Once the end of the list is reached, the same order repeats: the <code>-</code> shape falls first, sixth, 11th, 16th, etc.</p>
120 <p>The rocks don't spin, but they do get pushed around by jets of hot gas coming out of the walls themselves. A quick scan reveals the effect the jets of hot gas will have on the rocks as they fall (your puzzle input).</p>
121 <p>For example, suppose this was the jet pattern in your cave:</p>
122 <pre><code>&gt;&gt;&gt;&lt;&lt;&gt;&lt;&gt;&gt;&lt;&lt;&lt;&gt;&gt;&lt;&gt;&gt;&gt;&lt;&lt;&lt;&gt;&gt;&gt;&lt;&lt;&lt;&gt;&lt;&lt;&lt;&gt;&gt;&lt;&gt;&gt;&lt;&lt;&gt;&gt;
123 </code></pre>
124 <p>In jet patterns, <code>&lt;</code> means a push to the left, while <code>&gt;</code> means a push to the right. The pattern above means that the jets will push a falling rock right, then right, then right, then left, then left, then right, and so on. If the end of the list is reached, it repeats.</p>
125 <p>The tall, vertical chamber is exactly <em>seven units wide</em>. Each rock appears so that its left edge is two units away from the left wall and its bottom edge is three units above the highest rock in the room (or the floor, if there isn't one).</p>
126 <p>After a rock appears, it alternates between <em>being pushed by a jet of hot gas</em> one unit (in the direction indicated by the next symbol in the jet pattern) and then <em>falling one unit down</em>. If any movement would cause any part of the rock to move into the walls, floor, or a stopped rock, the movement instead does not occur. If a <em>downward</em> movement would have caused a falling rock to move into the floor or an already-fallen rock, the falling rock stops where it is (having landed on something) and a new rock immediately begins falling.</p>
127 <p>Drawing falling rocks with <code>@</code> and stopped rocks with <code>#</code>, the jet pattern in the example above manifests as follows:</p>
128 <pre><code>The first rock begins falling:
129 |..@@@@.|
130 |.......|
131 |.......|
132 |.......|
133 +-------+
134
135 Jet of gas pushes rock right:
136 |...@@@@|
137 |.......|
138 |.......|
139 |.......|
140 +-------+
141
142 Rock falls 1 unit:
143 |...@@@@|
144 |.......|
145 |.......|
146 +-------+
147
148 Jet of gas pushes rock right, but nothing happens:
149 |...@@@@|
150 |.......|
151 |.......|
152 +-------+
153
154 Rock falls 1 unit:
155 |...@@@@|
156 |.......|
157 +-------+
158
159 Jet of gas pushes rock right, but nothing happens:
160 |...@@@@|
161 |.......|
162 +-------+
163
164 Rock falls 1 unit:
165 |...@@@@|
166 +-------+
167
168 Jet of gas pushes rock left:
169 |..@@@@.|
170 +-------+
171
172 Rock falls 1 unit, causing it to come to rest:
173 |..####.|
174 +-------+
175
176 A new rock begins falling:
177 |...@...|
178 |..@@@..|
179 |...@...|
180 |.......|
181 |.......|
182 |.......|
183 |..####.|
184 +-------+
185
186 Jet of gas pushes rock left:
187 |..@....|
188 |.@@@...|
189 |..@....|
190 |.......|
191 |.......|
192 |.......|
193 |..####.|
194 +-------+
195
196 Rock falls 1 unit:
197 |..@....|
198 |.@@@...|
199 |..@....|
200 |.......|
201 |.......|
202 |..####.|
203 +-------+
204
205 Jet of gas pushes rock right:
206 |...@...|
207 |..@@@..|
208 |...@...|
209 |.......|
210 |.......|
211 |..####.|
212 +-------+
213
214 Rock falls 1 unit:
215 |...@...|
216 |..@@@..|
217 |...@...|
218 |.......|
219 |..####.|
220 +-------+
221
222 Jet of gas pushes rock left:
223 |..@....|
224 |.@@@...|
225 |..@....|
226 |.......|
227 |..####.|
228 +-------+
229
230 Rock falls 1 unit:
231 |..@....|
232 |.@@@...|
233 |..@....|
234 |..####.|
235 +-------+
236
237 Jet of gas pushes rock right:
238 |...@...|
239 |..@@@..|
240 |...@...|
241 |..####.|
242 +-------+
243
244 Rock falls 1 unit, causing it to come to rest:
245 |...#...|
246 |..###..|
247 |...#...|
248 |..####.|
249 +-------+
250
251 A new rock begins falling:
252 |....@..|
253 |....@..|
254 |..@@@..|
255 |.......|
256 |.......|
257 |.......|
258 |...#...|
259 |..###..|
260 |...#...|
261 |..####.|
262 +-------+
263 </code></pre>
264 <p>The moment each of the next few rocks begins falling, you would see this:</p>
265 <pre><code>|..@....|
266 |..@....|
267 |..@....|
268 |..@....|
269 |.......|
270 |.......|
271 |.......|
272 |..#....|
273 |..#....|
274 |####...|
275 |..###..|
276 |...#...|
277 |..####.|
278 +-------+
279
280 |..@@...|
281 |..@@...|
282 |.......|
283 |.......|
284 |.......|
285 |....#..|
286 |..#.#..|
287 |..#.#..|
288 |#####..|
289 |..###..|
290 |...#...|
291 |..####.|
292 +-------+
293
294 |..@@@@.|
295 |.......|
296 |.......|
297 |.......|
298 |....##.|
299 |....##.|
300 |....#..|
301 |..#.#..|
302 |..#.#..|
303 |#####..|
304 |..###..|
305 |...#...|
306 |..####.|
307 +-------+
308
309 |...@...|
310 |..@@@..|
311 |...@...|
312 |.......|
313 |.......|
314 |.......|
315 |.####..|
316 |....##.|
317 |....##.|
318 |....#..|
319 |..#.#..|
320 |..#.#..|
321 |#####..|
322 |..###..|
323 |...#...|
324 |..####.|
325 +-------+
326
327 |....@..|
328 |....@..|
329 |..@@@..|
330 |.......|
331 |.......|
332 |.......|
333 |..#....|
334 |.###...|
335 |..#....|
336 |.####..|
337 |....##.|
338 |....##.|
339 |....#..|
340 |..#.#..|
341 |..#.#..|
342 |#####..|
343 |..###..|
344 |...#...|
345 |..####.|
346 +-------+
347
348 |..@....|
349 |..@....|
350 |..@....|
351 |..@....|
352 |.......|
353 |.......|
354 |.......|
355 |.....#.|
356 |.....#.|
357 |..####.|
358 |.###...|
359 |..#....|
360 |.####..|
361 |....##.|
362 |....##.|
363 |....#..|
364 |..#.#..|
365 |..#.#..|
366 |#####..|
367 |..###..|
368 |...#...|
369 |..####.|
370 +-------+
371
372 |..@@...|
373 |..@@...|
374 |.......|
375 |.......|
376 |.......|
377 |....#..|
378 |....#..|
379 |....##.|
380 |....##.|
381 |..####.|
382 |.###...|
383 |..#....|
384 |.####..|
385 |....##.|
386 |....##.|
387 |....#..|
388 |..#.#..|
389 |..#.#..|
390 |#####..|
391 |..###..|
392 |...#...|
393 |..####.|
394 +-------+
395
396 |..@@@@.|
397 |.......|
398 |.......|
399 |.......|
400 |....#..|
401 |....#..|
402 |....##.|
403 |##..##.|
404 |######.|
405 |.###...|
406 |..#....|
407 |.####..|
408 |....##.|
409 |....##.|
410 |....#..|
411 |..#.#..|
412 |..#.#..|
413 |#####..|
414 |..###..|
415 |...#...|
416 |..####.|
417 +-------+
418 </code></pre>
419 <p>To prove to the elephants your simulation is accurate, they want to know how tall the tower will get after 2022 rocks have stopped (but before the 2023rd rock begins falling). In this example, the tower of rocks will be <code><em>3068</em></code> units tall.</p>
420 <p><em>How many units tall will the tower of rocks be after 2022 rocks have stopped falling?</em></p>
421 </article>
422 <p>Your puzzle answer was <code>3211</code>.</p><article class="day-desc"><h2 id="part2">--- Part Two ---</h2><p>The elephants are not impressed by your simulation. They demand to know how tall the tower will be after <code><em>1000000000000</em></code> rocks have stopped! Only then will they feel confident enough to proceed through the cave.</p>
423 <p>In the example above, the tower would be <code><em>1514285714288</em></code> units tall!</p>
424 <p><em>How tall will the tower be after <code>1000000000000</code> rocks have stopped?</em></p>
425 </article>
426 <p>Your puzzle answer was <code>1589142857183</code>.</p><p class="day-success">Both parts of this puzzle are complete! They provide two gold stars: **</p>
427 <p>At this point, you should <a href="/2022">return to your Advent calendar</a> and try another puzzle.</p>
428 <p>If you still want to see it, you can <a href="17/input" target="_blank">get your puzzle input</a>.</p>
429 <p>You can also <span class="share">[Share<span class="share-content">on
430 <a href="https://twitter.com/intent/tweet?text=I%27ve+completed+%22Pyroclastic+Flow%22+%2D+Day+17+%2D+Advent+of+Code+2022&amp;url=https%3A%2F%2Fadventofcode%2Ecom%2F2022%2Fday%2F17&amp;related=ericwastl&amp;hashtags=AdventOfCode" target="_blank">Twitter</a>
431 <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+%22Pyroclastic+Flow%22+%2D+Day+17+%2D+Advent+of+Code+2022+%23AdventOfCode+https%3A%2F%2Fadventofcode%2Ecom%2F2022%2Fday%2F17'}else{return false;}" target="_blank">Mastodon</a
432 ></span>]</span> this puzzle.</p>
433 </main>
434
435 <!-- ga -->
436 <script>
437 (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
438 (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
439 m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
440 })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
441 ga('create', 'UA-69522494-1', 'auto');
442 ga('set', 'anonymizeIp', true);
443 ga('send', 'pageview');
444 </script>
445 <!-- /ga -->
446 </body>
447 </html>