ea347bb765623fe17f96e8e923595843c951690e
[advent-of-code-20.git] / problems / day20.html
1 <!DOCTYPE html>
2 <html lang="en-us">
3 <head>
4 <meta charset="utf-8"/>
5 <title>Day 20 - Advent of Code 2020</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?25"/>
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 </head><!--
12
13
14
15
16 Oh, hello! Funny seeing you here.
17
18 I appreciate your enthusiasm, but you aren't going to find much down here.
19 There certainly aren't clues to any of the puzzles. The best surprises don't
20 even appear in the source until you unlock them for real.
21
22 Please be careful with automated requests; I'm not a massive company, and I can
23 only take so much traffic. Please be considerate so that everyone gets to play.
24
25 If you're curious about how Advent of Code works, it's running on some custom
26 Perl code. Other than a few integrations (auth, analytics, social media), I
27 built the whole thing myself, including the design, animations, prose, and all
28 of the puzzles.
29
30 The puzzles are most of the work; preparing a new calendar and a new set of
31 puzzles each year takes all of my free time for 4-5 months. A lot of effort
32 went into building this thing - I hope you're enjoying playing it as much as I
33 enjoyed making it for you!
34
35 If you'd like to hang out, I'm @ericwastl on Twitter.
36
37 - Eric Wastl
38
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 <body>
90 <header><div><h1 class="title-global"><a href="/">Advent of Code</a></h1><nav><ul><li><a href="/2020/about">[About]</a></li><li><a href="/2020/events">[Events]</a></li><li><a href="https://teespring.com/stores/advent-of-code" target="_blank">[Shop]</a></li><li><a href="/2020/settings">[Settings]</a></li><li><a href="/2020/auth/logout">[Log Out]</a></li></ul></nav><div class="user">Neil Smith <a href="/2020/support" class="supporter-badge" title="Advent of Code Supporter">(AoC++)</a> <span class="star-count">40*</span></div></div><div><h1 class="title-event">&nbsp;&nbsp;&nbsp;<span class="title-event-wrap">$year=</span><a href="/2020">2020</a><span class="title-event-wrap">;</span></h1><nav><ul><li><a href="/2020">[Calendar]</a></li><li><a href="/2020/support">[AoC++]</a></li><li><a href="/2020/sponsors">[Sponsors]</a></li><li><a href="/2020/leaderboard">[Leaderboard]</a></li><li><a href="/2020/stats">[Stats]</a></li></ul></nav></div></header>
91
92 <div id="sidebar">
93 <div id="sponsor"><div class="quiet">Our <a href="/2020/sponsors">sponsors</a> help make Advent of Code possible:</div><div class="sponsor"><a href="https://medium.com/building-trayio" target="_blank" onclick="if(ga)ga('send','event','sponsor','sidebar',this.href);" rel="noopener">tray.io</a> - Building a platform that connects people with technology.</div></div>
94 </div><!--/sidebar-->
95
96 <main>
97 <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>
98 <article class="day-desc"><h2>--- Day 20: Jurassic Jigsaw ---</h2><p>The high-speed train leaves the forest and quickly carries you south. You can even see a desert in the distance! Since you have some spare time, you <span title="Just in case. Maybe they missed something.">might as well</span> see if there was anything interesting in the image the Mythical Information Bureau satellite captured.</p>
99 <p>After decoding the satellite messages, you discover that the data actually contains many small images created by the satellite's <em>camera array</em>. The camera array consists of many cameras; rather than produce a single square image, they produce many smaller square image <em>tiles</em> that need to be <em>reassembled back into a single image</em>.</p>
100 <p>Each camera in the camera array returns a single monochrome <em>image tile</em> with a random unique <em>ID number</em>. The tiles (your puzzle input) arrived in a random order.</p>
101 <p>Worse yet, the camera array appears to be malfunctioning: each image tile has been <em>rotated and flipped to a random orientation</em>. Your first task is to reassemble the original image by orienting the tiles so they fit together.</p>
102 <p>To show how the tiles should be reassembled, each tile's image data includes a border that should line up exactly with its adjacent tiles. All tiles have this border, and the border lines up exactly when the tiles are both oriented correctly. Tiles at the edge of the image also have this border, but the outermost edges won't line up with any other tiles.</p>
103 <p>For example, suppose you have the following nine tiles:</p>
104 <pre><code>Tile 2311:
105 ..##.#..#.
106 ##..#.....
107 #...##..#.
108 ####.#...#
109 ##.##.###.
110 ##...#.###
111 .#.#.#..##
112 ..#....#..
113 ###...#.#.
114 ..###..###
115
116 Tile 1951:
117 #.##...##.
118 #.####...#
119 .....#..##
120 #...######
121 .##.#....#
122 .###.#####
123 ###.##.##.
124 .###....#.
125 ..#.#..#.#
126 #...##.#..
127
128 Tile 1171:
129 ####...##.
130 #..##.#..#
131 ##.#..#.#.
132 .###.####.
133 ..###.####
134 .##....##.
135 .#...####.
136 #.##.####.
137 ####..#...
138 .....##...
139
140 Tile 1427:
141 ###.##.#..
142 .#..#.##..
143 .#.##.#..#
144 #.#.#.##.#
145 ....#...##
146 ...##..##.
147 ...#.#####
148 .#.####.#.
149 ..#..###.#
150 ..##.#..#.
151
152 Tile 1489:
153 ##.#.#....
154 ..##...#..
155 .##..##...
156 ..#...#...
157 #####...#.
158 #..#.#.#.#
159 ...#.#.#..
160 ##.#...##.
161 ..##.##.##
162 ###.##.#..
163
164 Tile 2473:
165 #....####.
166 #..#.##...
167 #.##..#...
168 ######.#.#
169 .#...#.#.#
170 .#########
171 .###.#..#.
172 ########.#
173 ##...##.#.
174 ..###.#.#.
175
176 Tile 2971:
177 ..#.#....#
178 #...###...
179 #.#.###...
180 ##.##..#..
181 .#####..##
182 .#..####.#
183 #..#.#..#.
184 ..####.###
185 ..#.#.###.
186 ...#.#.#.#
187
188 Tile 2729:
189 ...#.#.#.#
190 ####.#....
191 ..#.#.....
192 ....#..#.#
193 .##..##.#.
194 .#.####...
195 ####.#.#..
196 ##.####...
197 ##..#.##..
198 #.##...##.
199
200 Tile 3079:
201 #.#.#####.
202 .#..######
203 ..#.......
204 ######....
205 ####.#..#.
206 .#...#.##.
207 #.#####.##
208 ..#.###...
209 ..#.......
210 ..#.###...
211 </code></pre>
212 <p>By rotating, flipping, and rearranging them, you can find a square arrangement that causes all adjacent borders to line up:</p>
213 <pre><code>#...##.#.. ..###..### #.#.#####.
214 ..#.#..#.# ###...#.#. .#..######
215 .###....#. ..#....#.. ..#.......
216 ###.##.##. .#.#.#..## ######....
217 .###.##### ##...#.### ####.#..#.
218 .##.#....# ##.##.###. .#...#.##.
219 #...###### ####.#...# #.#####.##
220 .....#..## #...##..#. ..#.###...
221 #.####...# ##..#..... ..#.......
222 #.##...##. ..##.#..#. ..#.###...
223
224 #.##...##. ..##.#..#. ..#.###...
225 ##..#.##.. ..#..###.# ##.##....#
226 ##.####... .#.####.#. ..#.###..#
227 ####.#.#.. ...#.##### ###.#..###
228 .#.####... ...##..##. .######.##
229 .##..##.#. ....#...## #.#.#.#...
230 ....#..#.# #.#.#.##.# #.###.###.
231 ..#.#..... .#.##.#..# #.###.##..
232 ####.#.... .#..#.##.. .######...
233 ...#.#.#.# ###.##.#.. .##...####
234
235 ...#.#.#.# ###.##.#.. .##...####
236 ..#.#.###. ..##.##.## #..#.##..#
237 ..####.### ##.#...##. .#.#..#.##
238 #..#.#..#. ...#.#.#.. .####.###.
239 .#..####.# #..#.#.#.# ####.###..
240 .#####..## #####...#. .##....##.
241 ##.##..#.. ..#...#... .####...#.
242 #.#.###... .##..##... .####.##.#
243 #...###... ..##...#.. ...#..####
244 ..#.#....# ##.#.#.... ...##.....
245 </code></pre>
246 <p>For reference, the IDs of the above tiles are:</p>
247 <pre><code><em>1951</em> 2311 <em>3079</em>
248 2729 1427 2473
249 <em>2971</em> 1489 <em>1171</em>
250 </code></pre>
251 <p>To check that you've assembled the image correctly, multiply the IDs of the four corner tiles together. If you do this with the assembled tiles from the example above, you get <code>1951 * 3079 * 2971 * 1171</code> = <em><code>20899048083289</code></em>.</p>
252 <p>Assemble the tiles into an image. <em>What do you get if you multiply together the IDs of the four corner tiles?</em></p>
253 </article>
254 <p>Your puzzle answer was <code>30425930368573</code>.</p><article class="day-desc"><h2 id="part2">--- Part Two ---</h2><p>Now, you're ready to <em>check the image for sea monsters</em>.</p>
255 <p>The borders of each tile are not part of the actual image; start by removing them.</p>
256 <p>In the example above, the tiles become:</p>
257 <pre><code>.#.#..#. ##...#.# #..#####
258 ###....# .#....#. .#......
259 ##.##.## #.#.#..# #####...
260 ###.#### #...#.## ###.#..#
261 ##.#.... #.##.### #...#.##
262 ...##### ###.#... .#####.#
263 ....#..# ...##..# .#.###..
264 .####... #..#.... .#......
265
266 #..#.##. .#..###. #.##....
267 #.####.. #.####.# .#.###..
268 ###.#.#. ..#.#### ##.#..##
269 #.####.. ..##..## ######.#
270 ##..##.# ...#...# .#.#.#..
271 ...#..#. .#.#.##. .###.###
272 .#.#.... #.##.#.. .###.##.
273 ###.#... #..#.##. ######..
274
275 .#.#.### .##.##.# ..#.##..
276 .####.## #.#...## #.#..#.#
277 ..#.#..# ..#.#.#. ####.###
278 #..####. ..#.#.#. ###.###.
279 #####..# ####...# ##....##
280 #.##..#. .#...#.. ####...#
281 .#.###.. ##..##.. ####.##.
282 ...###.. .##...#. ..#..###
283 </code></pre>
284 <p>Remove the gaps to form the actual image:</p>
285 <pre><code>.#.#..#.##...#.##..#####
286 ###....#.#....#..#......
287 ##.##.###.#.#..######...
288 ###.#####...#.#####.#..#
289 ##.#....#.##.####...#.##
290 ...########.#....#####.#
291 ....#..#...##..#.#.###..
292 .####...#..#.....#......
293 #..#.##..#..###.#.##....
294 #.####..#.####.#.#.###..
295 ###.#.#...#.######.#..##
296 #.####....##..########.#
297 ##..##.#...#...#.#.#.#..
298 ...#..#..#.#.##..###.###
299 .#.#....#.##.#...###.##.
300 ###.#...#..#.##.######..
301 .#.#.###.##.##.#..#.##..
302 .####.###.#...###.#..#.#
303 ..#.#..#..#.#.#.####.###
304 #..####...#.#.#.###.###.
305 #####..#####...###....##
306 #.##..#..#...#..####...#
307 .#.###..##..##..####.##.
308 ...###...##...#...#..###
309 </code></pre>
310 <p>Now, you're ready to search for sea monsters! Because your image is monochrome, a sea monster will look like this:</p>
311 <pre><code> #
312 # ## ## ###
313 # # # # # #
314 </code></pre>
315 <p>When looking for this pattern in the image, <em>the spaces can be anything</em>; only the <code>#</code> need to match. Also, you might need to rotate or flip your image before it's oriented correctly to find sea monsters. In the above image, <em>after flipping and rotating it</em> to the appropriate orientation, there are <em>two</em> sea monsters (marked with <code><em>O</em></code>):</p>
316 <pre><code>.####...#####..#...###..
317 #####..#..#.#.####..#.#.
318 .#.#...#.###...#.##.<em>O</em>#..
319 #.<em>O</em>.##.<em>O</em><em>O</em>#.#.<em>O</em><em>O</em>.##.<em>O</em><em>O</em><em>O</em>##
320 ..#<em>O</em>.#<em>O</em>#.<em>O</em>##<em>O</em>..<em>O</em>.#<em>O</em>##.##
321 ...#.#..##.##...#..#..##
322 #.##.#..#.#..#..##.#.#..
323 .###.##.....#...###.#...
324 #.####.#.#....##.#..#.#.
325 ##...#..#....#..#...####
326 ..#.##...###..#.#####..#
327 ....#.##.#.#####....#...
328 ..##.##.###.....#.##..#.
329 #...#...###..####....##.
330 .#.##...#.##.#.#.###...#
331 #.###.#..####...##..#...
332 #.###...#.##...#.##<em>O</em>###.
333 .<em>O</em>##.#<em>O</em><em>O</em>.###<em>O</em><em>O</em>##..<em>O</em><em>O</em><em>O</em>##.
334 ..<em>O</em>#.<em>O</em>..<em>O</em>..<em>O</em>.#<em>O</em>##<em>O</em>##.###
335 #.#..##.########..#..##.
336 #.#####..#.#...##..#....
337 #....##..#.#########..##
338 #...#.....#..##...###.##
339 #..###....##.#...##.##.#
340 </code></pre>
341 <p>Determine how rough the waters are in the sea monsters' habitat by counting the number of <code>#</code> that are <em>not</em> part of a sea monster. In the above example, the habitat's water roughness is <em><code>273</code></em>.</p>
342 <p><em>How many <code>#</code> are not part of a sea monster?</em></p>
343 </article>
344 <p>Your puzzle answer was <code>2453</code>.</p><p class="day-success">Both parts of this puzzle are complete! They provide two gold stars: **</p>
345 <p>At this point, you should <a href="/2020">return to your Advent calendar</a> and try another puzzle.</p>
346 <p>If you still want to see it, you can <a href="20/input" target="_blank">get your puzzle input</a>.</p>
347 <p>You can also <span class="share">[Share<span class="share-content">on
348 <a href="https://twitter.com/intent/tweet?text=I%27ve+completed+%22Jurassic+Jigsaw%22+%2D+Day+20+%2D+Advent+of+Code+2020&amp;url=https%3A%2F%2Fadventofcode%2Ecom%2F2020%2Fday%2F20&amp;related=ericwastl&amp;hashtags=AdventOfCode" target="_blank">Twitter</a>
349 <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+%22Jurassic+Jigsaw%22+%2D+Day+20+%2D+Advent+of+Code+2020+%23AdventOfCode+https%3A%2F%2Fadventofcode%2Ecom%2F2020%2Fday%2F20'}else{return false;}" target="_blank">Mastodon</a
350 ></span>]</span> this puzzle.</p>
351 </main>
352
353 <!-- ga -->
354 <script>
355 (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
356 (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
357 m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
358 })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
359 ga('create', 'UA-69522494-1', 'auto');
360 ga('set', 'anonymizeIp', true);
361 ga('send', 'pageview');
362 </script>
363 <!-- /ga -->
364 </body>
365 </html>