Tidying
[advent-of-code-22.git] / problems / day14.html
1 <!DOCTYPE html>
2 <html lang="en-us">
3 <head>
4 <meta charset="utf-8"/>
5 <title>Day 14 - 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">28*</span></div></div><div><h1 class="title-event">&nbsp;&nbsp;&nbsp;<span class="title-event-wrap">var y=</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://careers.bankofamerica.com/" target="_blank" onclick="if(ga)ga('send','event','sponsor','sidebar',this.href);" rel="noopener">Bank of America</a> - We use technology, models and data to make financial lives better for our clients and communities.</div></div>
95 </div><!--/sidebar-->
96
97 <main>
98 <article class="day-desc"><h2>--- Day 14: Regolith Reservoir ---</h2><p>The distress signal leads you to a giant waterfall! Actually, hang on - the signal seems like it's coming from the waterfall itself, and that doesn't make any sense. However, you do notice a little path that leads <em>behind</em> the waterfall.</p>
99 <p>Correction: the distress signal leads you behind a giant waterfall! There seems to be a large cave system here, and the signal definitely leads further inside.</p>
100 <p>As you begin to make your way deeper underground, you feel the ground rumble for a moment. Sand begins pouring into the cave! If you don't quickly figure out where the sand is going, you could quickly become trapped!</p>
101 <p>Fortunately, your <a href="/2018/day/17">familiarity</a> with analyzing the path of falling material will come in handy here. You scan a two-dimensional vertical slice of the cave above you (your puzzle input) and discover that it is mostly <em>air</em> with structures made of <em>rock</em>.</p>
102 <p>Your scan traces the path of each solid rock structure and reports the <code>x,y</code> coordinates that form the shape of the path, where <code>x</code> represents distance to the right and <code>y</code> represents distance down. Each path appears as a single line of text in your scan. After the first point of each path, each point indicates the end of a straight horizontal or vertical line to be drawn from the previous point. For example:</p>
103 <pre><code>498,4 -&gt; 498,6 -&gt; 496,6
104 503,4 -&gt; 502,4 -&gt; 502,9 -&gt; 494,9
105 </code></pre>
106 <p>This scan means that there are two paths of rock; the first path consists of two straight lines, and the second path consists of three straight lines. (Specifically, the first path consists of a line of rock from <code>498,4</code> through <code>498,6</code> and another line of rock from <code>498,6</code> through <code>496,6</code>.)</p>
107 <p>The sand is pouring into the cave from point <code>500,0</code>.</p>
108 <p>Drawing rock as <code>#</code>, air as <code>.</code>, and the source of the sand as <code>+</code>, this becomes:</p>
109 <pre><code>
110 4 5 5
111 9 0 0
112 4 0 3
113 0 ......+...
114 1 ..........
115 2 ..........
116 3 ..........
117 4 ....#...##
118 5 ....#...#.
119 6 ..###...#.
120 7 ........#.
121 8 ........#.
122 9 #########.
123 </code></pre>
124 <p>Sand is produced <em>one unit at a time</em>, and the next unit of sand is not produced until the previous unit of sand <em>comes to rest</em>. A unit of sand is large enough to fill one tile of air in your scan.</p>
125 <p>A unit of sand always falls <em>down one step</em> if possible. If the tile immediately below is blocked (by rock or sand), the unit of sand attempts to instead move diagonally <em>one step down and to the left</em>. If that tile is blocked, the unit of sand attempts to instead move diagonally <em>one step down and to the right</em>. Sand keeps moving as long as it is able to do so, at each step trying to move down, then down-left, then down-right. If all three possible destinations are blocked, the unit of sand <em>comes to rest</em> and no longer moves, at which point the next unit of sand is created back at the source.</p>
126 <p>So, drawing sand that has come to rest as <code>o</code>, the first unit of sand simply falls straight down and then stops:</p>
127 <pre><code>......+...
128 ..........
129 ..........
130 ..........
131 ....#...##
132 ....#...#.
133 ..###...#.
134 ........#.
135 ......<em>o</em>.#.
136 #########.
137 </code></pre>
138 <p>The second unit of sand then falls straight down, lands on the first one, and then comes to rest to its left:</p>
139 <pre><code>......+...
140 ..........
141 ..........
142 ..........
143 ....#...##
144 ....#...#.
145 ..###...#.
146 ........#.
147 .....oo.#.
148 #########.
149 </code></pre>
150 <p>After a total of five units of sand have come to rest, they form this pattern:</p>
151 <pre><code>......+...
152 ..........
153 ..........
154 ..........
155 ....#...##
156 ....#...#.
157 ..###...#.
158 ......o.#.
159 ....oooo#.
160 #########.
161 </code></pre>
162 <p>After a total of 22 units of sand:</p>
163 <pre><code>......+...
164 ..........
165 ......o...
166 .....ooo..
167 ....#ooo##
168 ....#ooo#.
169 ..###ooo#.
170 ....oooo#.
171 ...ooooo#.
172 #########.
173 </code></pre>
174 <p>Finally, only two more units of sand can possibly come to rest:</p>
175 <pre><code>......+...
176 ..........
177 ......o...
178 .....ooo..
179 ....#ooo##
180 ...<em>o</em>#ooo#.
181 ..###ooo#.
182 ....oooo#.
183 .<em>o</em>.ooooo#.
184 #########.
185 </code></pre>
186 <p>Once all <code><em>24</em></code> units of sand shown above have come to rest, all further sand flows out the bottom, falling into the endless void. Just for fun, the path any new sand takes before falling forever is shown here with <code>~</code>:</p>
187 <pre><code>.......+...
188 .......~...
189 ......~o...
190 .....~ooo..
191 ....~#ooo##
192 ...~o#ooo#.
193 ..~###ooo#.
194 ..~..oooo#.
195 .~o.ooooo#.
196 ~#########.
197 ~..........
198 ~..........
199 ~..........
200 </code></pre>
201 <p>Using your scan, simulate the falling sand. <em>How many units of sand come to rest before sand starts flowing into the abyss below?</em></p>
202 </article>
203 <p>Your puzzle answer was <code>644</code>.</p><article class="day-desc"><h2 id="part2">--- Part Two ---</h2><p>You realize you misread the scan. There isn't an <span title="Endless Void is my C cover band.">endless void</span> at the bottom of the scan - there's floor, and you're standing on it!</p>
204 <p>You don't have time to scan the floor, so assume the floor is an infinite horizontal line with a <code>y</code> coordinate equal to <em>two plus the highest <code>y</code> coordinate</em> of any point in your scan.</p>
205 <p>In the example above, the highest <code>y</code> coordinate of any point is <code>9</code>, and so the floor is at <code>y=11</code>. (This is as if your scan contained one extra rock path like <code>-infinity,11 -&gt; infinity,11</code>.) With the added floor, the example above now looks like this:</p>
206 <pre><code> ...........+........
207 ....................
208 ....................
209 ....................
210 .........#...##.....
211 .........#...#......
212 .......###...#......
213 .............#......
214 .............#......
215 .....#########......
216 ....................
217 &lt;-- etc #################### etc --&gt;
218 </code></pre>
219 <p>To find somewhere safe to stand, you'll need to simulate falling sand until a unit of sand comes to rest at <code>500,0</code>, blocking the source entirely and stopping the flow of sand into the cave. In the example above, the situation finally looks like this after <code><em>93</em></code> units of sand come to rest:</p>
220 <pre><code>............o............
221 ...........ooo...........
222 ..........ooooo..........
223 .........ooooooo.........
224 ........oo#ooo##o........
225 .......ooo#ooo#ooo.......
226 ......oo###ooo#oooo......
227 .....oooo.oooo#ooooo.....
228 ....oooooooooo#oooooo....
229 ...ooo#########ooooooo...
230 ..ooooo.......ooooooooo..
231 #########################
232 </code></pre>
233 <p>Using your scan, simulate the falling sand until the source of the sand becomes blocked. <em>How many units of sand come to rest?</em></p>
234 </article>
235 <p>Your puzzle answer was <code>27324</code>.</p><p class="day-success">Both parts of this puzzle are complete! They provide two gold stars: **</p>
236 <p>At this point, you should <a href="/2022">return to your Advent calendar</a> and try another puzzle.</p>
237 <p>If you still want to see it, you can <a href="14/input" target="_blank">get your puzzle input</a>.</p>
238 <p>You can also <span class="share">[Share<span class="share-content">on
239 <a href="https://twitter.com/intent/tweet?text=I%27ve+completed+%22Regolith+Reservoir%22+%2D+Day+14+%2D+Advent+of+Code+2022&amp;url=https%3A%2F%2Fadventofcode%2Ecom%2F2022%2Fday%2F14&amp;related=ericwastl&amp;hashtags=AdventOfCode" target="_blank">Twitter</a>
240 <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+%22Regolith+Reservoir%22+%2D+Day+14+%2D+Advent+of+Code+2022+%23AdventOfCode+https%3A%2F%2Fadventofcode%2Ecom%2F2022%2Fday%2F14'}else{return false;}" target="_blank">Mastodon</a
241 ></span>]</span> this puzzle.</p>
242 </main>
243
244 <!-- ga -->
245 <script>
246 (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
247 (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
248 m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
249 })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
250 ga('create', 'UA-69522494-1', 'auto');
251 ga('set', 'anonymizeIp', true);
252 ga('send', 'pageview');
253 </script>
254 <!-- /ga -->
255 </body>
256 </html>