Done day 22
[advent-of-code-21.git] / problems / day19.html
1 <!DOCTYPE html>
2 <html lang="en-us">
3 <head>
4 <meta charset="utf-8"/>
5 <title>Day 19 - Advent of Code 2021</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?26"/>
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="/2021/about">[About]</a></li><li><a href="/2021/events">[Events]</a></li><li><a href="https://teespring.com/stores/advent-of-code" target="_blank">[Shop]</a></li><li><a href="/2021/settings">[Settings]</a></li><li><a href="/2021/auth/logout">[Log Out]</a></li></ul></nav><div class="user">Neil Smith <a href="/2021/support" class="supporter-badge" title="Advent of Code Supporter">(AoC++)</a> <span class="star-count">38*</span></div></div><div><h1 class="title-event">&nbsp;&nbsp;&nbsp;<span class="title-event-wrap">0xffff&amp;</span><a href="/2021">2021</a><span class="title-event-wrap"></span></h1><nav><ul><li><a href="/2021">[Calendar]</a></li><li><a href="/2021/support">[AoC++]</a></li><li><a href="/2021/sponsors">[Sponsors]</a></li><li><a href="/2021/leaderboard">[Leaderboard]</a></li><li><a href="/2021/stats">[Stats]</a></li></ul></nav></div></header>
91
92 <div id="sidebar">
93 <div id="sponsor"><div class="quiet">Our <a href="/2021/sponsors">sponsors</a> help make Advent of Code possible:</div><div class="sponsor"><a href="https://www.twilio.com/quest" target="_blank" onclick="if(ga)ga('send','event','sponsor','sidebar',this.href);" rel="noopener">TwilioQuest</a> - Learn to code and lead your intrepid crew on a mission to save The Cloud in TwilioQuest, a PC role-playing game inspired by classics of the 16-bit era. Free forever, and available now for Windows, Mac, and Linux.</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 19: Beacon Scanner ---</h2><p>As your <a href="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>
99 <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>
100 <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>
101 <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>
102 <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>
103 <p>For a moment, consider only two dimensions. Suppose you have the following scanner reports:</p>
104 <pre><code>--- scanner 0 ---
105 0,2
106 4,1
107 3,3
108
109 --- scanner 1 ---
110 -1,-1
111 -5,0
112 -2,1
113 </code></pre>
114 <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>
115 <pre><code>...B.
116 B....
117 ....B
118 S....
119 </code></pre>
120 <p>Scanner <code>1</code> detects this:</p>
121 <pre><code>...B..
122 B....S
123 ....B.
124 </code></pre>
125 <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>
126 <pre><code>...B..
127 B....S
128 ....B.
129 S.....
130 </code></pre>
131 <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>
132 <p>For example, here is an arrangement of beacons as seen from a scanner in the same position but in different orientations:</p>
133 <pre><code>--- scanner 0 ---
134 -1,-1,1
135 -2,-2,2
136 -3,-3,3
137 -2,-3,1
138 5,6,-4
139 8,0,7
140
141 --- scanner 0 ---
142 1,-1,1
143 2,-2,2
144 3,-3,3
145 2,-1,3
146 -5,4,-6
147 -8,-7,0
148
149 --- scanner 0 ---
150 -1,-1,-1
151 -2,-2,-2
152 -3,-3,-3
153 -1,-3,-2
154 4,6,5
155 -7,0,8
156
157 --- scanner 0 ---
158 1,1,-1
159 2,2,-2
160 3,3,-3
161 1,3,-2
162 -4,-6,5
163 7,0,8
164
165 --- scanner 0 ---
166 1,1,1
167 2,2,2
168 3,3,3
169 3,1,2
170 -6,-4,-5
171 0,7,-8
172 </code></pre>
173 <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>
174 <pre><code>--- scanner 0 ---
175 404,-588,-901
176 528,-643,409
177 -838,591,734
178 390,-675,-793
179 -537,-823,-458
180 -485,-357,347
181 -345,-311,381
182 -661,-816,-575
183 -876,649,763
184 -618,-824,-621
185 553,345,-567
186 474,580,667
187 -447,-329,318
188 -584,868,-557
189 544,-627,-890
190 564,392,-477
191 455,729,728
192 -892,524,684
193 -689,845,-530
194 423,-701,434
195 7,-33,-71
196 630,319,-379
197 443,580,662
198 -789,900,-551
199 459,-707,401
200
201 --- scanner 1 ---
202 686,422,578
203 605,423,415
204 515,917,-361
205 -336,658,858
206 95,138,22
207 -476,619,847
208 -340,-569,-846
209 567,-361,727
210 -460,603,-452
211 669,-402,600
212 729,430,532
213 -500,-761,534
214 -322,571,750
215 -466,-666,-811
216 -429,-592,574
217 -355,545,-477
218 703,-491,-529
219 -328,-685,520
220 413,935,-424
221 -391,539,-444
222 586,-435,557
223 -364,-763,-893
224 807,-499,-711
225 755,-354,-619
226 553,889,-390
227
228 --- scanner 2 ---
229 649,640,665
230 682,-795,504
231 -784,533,-524
232 -644,584,-595
233 -588,-843,648
234 -30,6,44
235 -674,560,763
236 500,723,-460
237 609,671,-379
238 -555,-800,653
239 -675,-892,-343
240 697,-426,-610
241 578,704,681
242 493,664,-388
243 -671,-858,530
244 -667,343,800
245 571,-461,-707
246 -138,-166,112
247 -889,563,-600
248 646,-828,498
249 640,759,510
250 -630,509,768
251 -681,-892,-333
252 673,-379,-804
253 -742,-814,-386
254 577,-820,562
255
256 --- scanner 3 ---
257 -589,542,597
258 605,-692,669
259 -500,565,-823
260 -660,373,557
261 -458,-679,-417
262 -488,449,543
263 -626,468,-788
264 338,-750,-386
265 528,-832,-391
266 562,-778,733
267 -938,-730,414
268 543,643,-506
269 -524,371,-870
270 407,773,750
271 -104,29,83
272 378,-903,-323
273 -778,-728,485
274 426,699,580
275 -438,-605,-362
276 -469,-447,-387
277 509,732,623
278 647,635,-688
279 -868,-804,481
280 614,-800,639
281 595,780,-596
282
283 --- scanner 4 ---
284 727,592,562
285 -293,-554,779
286 441,611,-461
287 -714,465,-776
288 -743,427,-804
289 -660,-479,-426
290 832,-632,460
291 927,-485,-438
292 408,393,-506
293 466,436,-512
294 110,16,151
295 -258,-428,682
296 -393,719,612
297 -211,-452,876
298 808,-476,-593
299 -575,615,604
300 -485,667,467
301 -680,325,-822
302 -627,-443,-432
303 872,-547,-609
304 833,512,582
305 807,604,487
306 839,-516,451
307 891,-625,532
308 -652,-548,-490
309 30,-46,-14
310 </code></pre>
311 <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>
312 <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>
313 <pre><code>-618,-824,-621
314 -537,-823,-458
315 -447,-329,318
316 404,-588,-901
317 544,-627,-890
318 528,-643,409
319 -661,-816,-575
320 390,-675,-793
321 423,-701,434
322 -345,-311,381
323 459,-707,401
324 -485,-357,347
325 </code></pre>
326 <p>These same 12 beacons (in the same order) but from the perspective of scanner <code>1</code> are:</p>
327 <pre><code>686,422,578
328 605,423,415
329 515,917,-361
330 -336,658,858
331 -476,619,847
332 -460,603,-452
333 729,430,532
334 -322,571,750
335 -355,545,-477
336 413,935,-424
337 -391,539,-444
338 553,889,-390
339 </code></pre>
340 <p>Because of this, scanner <code>1</code> must be at <code>68,-1246,-43</code> (relative to scanner <code>0</code>).</p>
341 <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>
342 <pre><code>459,-707,401
343 -739,-1745,668
344 -485,-357,347
345 432,-2009,850
346 528,-643,409
347 423,-701,434
348 -345,-311,381
349 408,-1815,803
350 534,-1912,768
351 -687,-1600,576
352 -447,-329,318
353 -635,-1737,486
354 </code></pre>
355 <p>So, scanner <code>4</code> is at <code>-20,-1133,1061</code> (relative to scanner <code>0</code>).</p>
356 <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>
357 <p>The full list of beacons (relative to scanner <code>0</code>) is:</p>
358 <pre><code>-892,524,684
359 -876,649,763
360 -838,591,734
361 -789,900,-551
362 -739,-1745,668
363 -706,-3180,-659
364 -697,-3072,-689
365 -689,845,-530
366 -687,-1600,576
367 -661,-816,-575
368 -654,-3158,-753
369 -635,-1737,486
370 -631,-672,1502
371 -624,-1620,1868
372 -620,-3212,371
373 -618,-824,-621
374 -612,-1695,1788
375 -601,-1648,-643
376 -584,868,-557
377 -537,-823,-458
378 -532,-1715,1894
379 -518,-1681,-600
380 -499,-1607,-770
381 -485,-357,347
382 -470,-3283,303
383 -456,-621,1527
384 -447,-329,318
385 -430,-3130,366
386 -413,-627,1469
387 -345,-311,381
388 -36,-1284,1171
389 -27,-1108,-65
390 7,-33,-71
391 12,-2351,-103
392 26,-1119,1091
393 346,-2985,342
394 366,-3059,397
395 377,-2827,367
396 390,-675,-793
397 396,-1931,-563
398 404,-588,-901
399 408,-1815,803
400 423,-701,434
401 432,-2009,850
402 443,580,662
403 455,729,728
404 456,-540,1869
405 459,-707,401
406 465,-695,1988
407 474,580,667
408 496,-1584,1900
409 497,-1838,-617
410 527,-524,1933
411 528,-643,409
412 534,-1912,768
413 544,-627,-890
414 553,345,-567
415 564,392,-477
416 568,-2007,-577
417 605,-1665,1952
418 612,-1593,1893
419 630,319,-379
420 686,-3108,-505
421 776,-3184,-501
422 846,-3110,-434
423 1135,-1161,1235
424 1243,-1093,1063
425 1660,-552,429
426 1693,-557,386
427 1735,-437,1738
428 1749,-1800,1813
429 1772,-405,1572
430 1776,-675,371
431 1779,-442,1789
432 1780,-1548,337
433 1786,-1538,337
434 1847,-1591,415
435 1889,-1729,1762
436 1994,-1805,1792
437 </code></pre>
438 <p>In total, there are <code><em>79</em></code> beacons.</p>
439 <p>Assemble the full map of beacons. <em>How many beacons are there?</em></p>
440 </article>
441 <p>Your puzzle answer was <code>355</code>.</p><article class="day-desc"><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>
442 <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>
443 <p><em>What is the largest Manhattan distance between any two scanners?</em></p>
444 </article>
445 <p>Your puzzle answer was <code>10842</code>.</p><p class="day-success">Both parts of this puzzle are complete! They provide two gold stars: **</p>
446 <p>At this point, you should <a href="/2021">return to your Advent calendar</a> and try another puzzle.</p>
447 <p>If you still want to see it, you can <a href="19/input" target="_blank">get your puzzle input</a>.</p>
448 <p>You can also <span class="share">[Share<span class="share-content">on
449 <a href="https://twitter.com/intent/tweet?text=I%27ve+completed+%22Beacon+Scanner%22+%2D+Day+19+%2D+Advent+of+Code+2021&amp;url=https%3A%2F%2Fadventofcode%2Ecom%2F2021%2Fday%2F19&amp;related=ericwastl&amp;hashtags=AdventOfCode" target="_blank">Twitter</a>
450 <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+%22Beacon+Scanner%22+%2D+Day+19+%2D+Advent+of+Code+2021+%23AdventOfCode+https%3A%2F%2Fadventofcode%2Ecom%2F2021%2Fday%2F19'}else{return false;}" target="_blank">Mastodon</a
451 ></span>]</span> this puzzle.</p>
452 </main>
453
454 <!-- ga -->
455 <script>
456 (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
457 (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
458 m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
459 })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
460 ga('create', 'UA-69522494-1', 'auto');
461 ga('set', 'anonymizeIp', true);
462 ga('send', 'pageview');
463 </script>
464 <!-- /ga -->
465 </body>
466 </html>