Done day 22
[advent-of-code-21.git] / problems / day22.html
1 <!DOCTYPE html>
2 <html lang="en-us">
3 <head>
4 <meta charset="utf-8"/>
5 <title>Day 22 - 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">44*</span></div></div><div><h1 class="title-event">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="title-event-wrap">λy.</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://blog.scottlogic.com/category/tech.html" target="_blank" onclick="if(ga)ga('send','event','sponsor','sidebar',this.href);" rel="noopener">Scott Logic</a> - Check out our tech blog if you&apos;re interested in joining a smart, inclusive community. Have a great and safe Christmas!</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 22: Reactor Reboot ---</h2><p>Operating at these extreme ocean depths has overloaded the submarine's reactor; it needs to be rebooted.</p>
99 <p>The reactor core is made up of a large 3-dimensional grid made up entirely of cubes, one cube per integer 3-dimensional coordinate (<code>x,y,z</code>). Each cube can be either <em>on</em> or <em>off</em>; at the start of the reboot process, they are all <em>off</em>. (Could it be an old model of a reactor you've seen <a href="/2020/day/17">before</a>?)</p>
100 <p>To reboot the reactor, you just need to set all of the cubes to either <em>on</em> or <em>off</em> by following a list of <em>reboot steps</em> (your puzzle input). Each step specifies a <a href="https://en.wikipedia.org/wiki/Cuboid" target="_blank">cuboid</a> (the set of all cubes that have coordinates which fall within ranges for <code>x</code>, <code>y</code>, and <code>z</code>) and whether to turn all of the cubes in that cuboid <em>on</em> or <em>off</em>.</p>
101 <p>For example, given these reboot steps:</p>
102 <pre><code>on x=10..12,y=10..12,z=10..12
103 on x=11..13,y=11..13,z=11..13
104 off x=9..11,y=9..11,z=9..11
105 on x=10..10,y=10..10,z=10..10
106 </code></pre>
107 <p>The first step (<code>on x=10..12,y=10..12,z=10..12</code>) turns <em>on</em> a 3x3x3 cuboid consisting of 27 cubes:</p>
108 <ul>
109 <li><code>10,10,10</code></li>
110 <li><code>10,10,11</code></li>
111 <li><code>10,10,12</code></li>
112 <li><code>10,11,10</code></li>
113 <li><code>10,11,11</code></li>
114 <li><code>10,11,12</code></li>
115 <li><code>10,12,10</code></li>
116 <li><code>10,12,11</code></li>
117 <li><code>10,12,12</code></li>
118 <li><code>11,10,10</code></li>
119 <li><code>11,10,11</code></li>
120 <li><code>11,10,12</code></li>
121 <li><code>11,11,10</code></li>
122 <li><code>11,11,11</code></li>
123 <li><code>11,11,12</code></li>
124 <li><code>11,12,10</code></li>
125 <li><code>11,12,11</code></li>
126 <li><code>11,12,12</code></li>
127 <li><code>12,10,10</code></li>
128 <li><code>12,10,11</code></li>
129 <li><code>12,10,12</code></li>
130 <li><code>12,11,10</code></li>
131 <li><code>12,11,11</code></li>
132 <li><code>12,11,12</code></li>
133 <li><code>12,12,10</code></li>
134 <li><code>12,12,11</code></li>
135 <li><code>12,12,12</code></li>
136 </ul>
137 <p>The second step (<code>on x=11..13,y=11..13,z=11..13</code>) turns <em>on</em> a 3x3x3 cuboid that overlaps with the first. As a result, only 19 additional cubes turn on; the rest are already on from the previous step:</p>
138 <ul>
139 <li><code>11,11,13</code></li>
140 <li><code>11,12,13</code></li>
141 <li><code>11,13,11</code></li>
142 <li><code>11,13,12</code></li>
143 <li><code>11,13,13</code></li>
144 <li><code>12,11,13</code></li>
145 <li><code>12,12,13</code></li>
146 <li><code>12,13,11</code></li>
147 <li><code>12,13,12</code></li>
148 <li><code>12,13,13</code></li>
149 <li><code>13,11,11</code></li>
150 <li><code>13,11,12</code></li>
151 <li><code>13,11,13</code></li>
152 <li><code>13,12,11</code></li>
153 <li><code>13,12,12</code></li>
154 <li><code>13,12,13</code></li>
155 <li><code>13,13,11</code></li>
156 <li><code>13,13,12</code></li>
157 <li><code>13,13,13</code></li>
158 </ul>
159 <p>The third step (<code>off x=9..11,y=9..11,z=9..11</code>) turns <em>off</em> a 3x3x3 cuboid that overlaps partially with some cubes that are on, ultimately turning off 8 cubes:</p>
160 <ul>
161 <li><code>10,10,10</code></li>
162 <li><code>10,10,11</code></li>
163 <li><code>10,11,10</code></li>
164 <li><code>10,11,11</code></li>
165 <li><code>11,10,10</code></li>
166 <li><code>11,10,11</code></li>
167 <li><code>11,11,10</code></li>
168 <li><code>11,11,11</code></li>
169 </ul>
170 <p>The final step (<code>on x=10..10,y=10..10,z=10..10</code>) turns <em>on</em> a single cube, <code>10,10,10</code>. After this last step, <code><em>39</em></code> cubes are <em>on</em>.</p>
171 <p>The initialization procedure only uses cubes that have <code>x</code>, <code>y</code>, and <code>z</code> positions of at least <code>-50</code> and at most <code>50</code>. For now, ignore cubes outside this region.</p>
172 <p>Here is a larger example:</p>
173 <pre><code>on x=-20..26,y=-36..17,z=-47..7
174 on x=-20..33,y=-21..23,z=-26..28
175 on x=-22..28,y=-29..23,z=-38..16
176 on x=-46..7,y=-6..46,z=-50..-1
177 on x=-49..1,y=-3..46,z=-24..28
178 on x=2..47,y=-22..22,z=-23..27
179 on x=-27..23,y=-28..26,z=-21..29
180 on x=-39..5,y=-6..47,z=-3..44
181 on x=-30..21,y=-8..43,z=-13..34
182 on x=-22..26,y=-27..20,z=-29..19
183 off x=-48..-32,y=26..41,z=-47..-37
184 on x=-12..35,y=6..50,z=-50..-2
185 off x=-48..-32,y=-32..-16,z=-15..-5
186 on x=-18..26,y=-33..15,z=-7..46
187 off x=-40..-22,y=-38..-28,z=23..41
188 on x=-16..35,y=-41..10,z=-47..6
189 off x=-32..-23,y=11..30,z=-14..3
190 on x=-49..-5,y=-3..45,z=-29..18
191 off x=18..30,y=-20..-8,z=-3..13
192 on x=-41..9,y=-7..43,z=-33..15
193 on x=-54112..-39298,y=-85059..-49293,z=-27449..7877
194 on x=967..23432,y=45373..81175,z=27513..53682
195 </code></pre>
196 <p>The last two steps are fully outside the initialization procedure area; all other steps are fully within it. After executing these steps in the initialization procedure region, <code><em>590784</em></code> cubes are <em>on</em>.</p>
197 <p>Execute the reboot steps. Afterward, considering only cubes in the region <code>x=-50..50,y=-50..50,z=-50..50</code>, <em>how many cubes are on?</em></p>
198 </article>
199 <p>Your puzzle answer was <code>545118</code>.</p><article class="day-desc"><h2 id="part2">--- Part Two ---</h2><p>Now that the initialization procedure is complete, you can reboot the reactor.</p>
200 <p>Starting with all cubes <em>off</em>, run all of the <em>reboot steps</em> for all cubes in the reactor.</p>
201 <p>Consider the following reboot steps:</p>
202 <pre><code>on x=-5..47,y=-31..22,z=-19..33
203 on x=-44..5,y=-27..21,z=-14..35
204 on x=-49..-1,y=-11..42,z=-10..38
205 on x=-20..34,y=-40..6,z=-44..1
206 off x=26..39,y=40..50,z=-2..11
207 on x=-41..5,y=-41..6,z=-36..8
208 off x=-43..-33,y=-45..-28,z=7..25
209 on x=-33..15,y=-32..19,z=-34..11
210 off x=35..47,y=-46..-34,z=-11..5
211 on x=-14..36,y=-6..44,z=-16..29
212 on x=-57795..-6158,y=29564..72030,z=20435..90618
213 on x=36731..105352,y=-21140..28532,z=16094..90401
214 on x=30999..107136,y=-53464..15513,z=8553..71215
215 on x=13528..83982,y=-99403..-27377,z=-24141..23996
216 on x=-72682..-12347,y=18159..111354,z=7391..80950
217 on x=-1060..80757,y=-65301..-20884,z=-103788..-16709
218 on x=-83015..-9461,y=-72160..-8347,z=-81239..-26856
219 on x=-52752..22273,y=-49450..9096,z=54442..119054
220 on x=-29982..40483,y=-108474..-28371,z=-24328..38471
221 on x=-4958..62750,y=40422..118853,z=-7672..65583
222 on x=55694..108686,y=-43367..46958,z=-26781..48729
223 on x=-98497..-18186,y=-63569..3412,z=1232..88485
224 on x=-726..56291,y=-62629..13224,z=18033..85226
225 on x=-110886..-34664,y=-81338..-8658,z=8914..63723
226 on x=-55829..24974,y=-16897..54165,z=-121762..-28058
227 on x=-65152..-11147,y=22489..91432,z=-58782..1780
228 on x=-120100..-32970,y=-46592..27473,z=-11695..61039
229 on x=-18631..37533,y=-124565..-50804,z=-35667..28308
230 on x=-57817..18248,y=49321..117703,z=5745..55881
231 on x=14781..98692,y=-1341..70827,z=15753..70151
232 on x=-34419..55919,y=-19626..40991,z=39015..114138
233 on x=-60785..11593,y=-56135..2999,z=-95368..-26915
234 on x=-32178..58085,y=17647..101866,z=-91405..-8878
235 on x=-53655..12091,y=50097..105568,z=-75335..-4862
236 on x=-111166..-40997,y=-71714..2688,z=5609..50954
237 on x=-16602..70118,y=-98693..-44401,z=5197..76897
238 on x=16383..101554,y=4615..83635,z=-44907..18747
239 off x=-95822..-15171,y=-19987..48940,z=10804..104439
240 on x=-89813..-14614,y=16069..88491,z=-3297..45228
241 on x=41075..99376,y=-20427..49978,z=-52012..13762
242 on x=-21330..50085,y=-17944..62733,z=-112280..-30197
243 on x=-16478..35915,y=36008..118594,z=-7885..47086
244 off x=-98156..-27851,y=-49952..43171,z=-99005..-8456
245 off x=2032..69770,y=-71013..4824,z=7471..94418
246 on x=43670..120875,y=-42068..12382,z=-24787..38892
247 off x=37514..111226,y=-45862..25743,z=-16714..54663
248 off x=25699..97951,y=-30668..59918,z=-15349..69697
249 off x=-44271..17935,y=-9516..60759,z=49131..112598
250 on x=-61695..-5813,y=40978..94975,z=8655..80240
251 off x=-101086..-9439,y=-7088..67543,z=33935..83858
252 off x=18020..114017,y=-48931..32606,z=21474..89843
253 off x=-77139..10506,y=-89994..-18797,z=-80..59318
254 off x=8476..79288,y=-75520..11602,z=-96624..-24783
255 on x=-47488..-1262,y=24338..100707,z=16292..72967
256 off x=-84341..13987,y=2429..92914,z=-90671..-1318
257 off x=-37810..49457,y=-71013..-7894,z=-105357..-13188
258 off x=-27365..46395,y=31009..98017,z=15428..76570
259 off x=-70369..-16548,y=22648..78696,z=-1892..86821
260 on x=-53470..21291,y=-120233..-33476,z=-44150..38147
261 off x=-93533..-4276,y=-16170..68771,z=-104985..-24507
262 </code></pre>
263 <p>After running the above reboot steps, <code><em>2758514936282235</em></code> cubes are <em>on</em>. (Just for <span title="Well, *I* think it's fun.">fun</span>, <code>474140</code> of those are also in the initialization procedure region.)</p>
264 <p>Starting again with all cubes <em>off</em>, execute all reboot steps. Afterward, considering all cubes, <em>how many cubes are on?</em></p>
265 </article>
266 <p>Your puzzle answer was <code>1227298136842375</code>.</p><p class="day-success">Both parts of this puzzle are complete! They provide two gold stars: **</p>
267 <p>At this point, you should <a href="/2021">return to your Advent calendar</a> and try another puzzle.</p>
268 <p>If you still want to see it, you can <a href="22/input" target="_blank">get your puzzle input</a>.</p>
269 <p>You can also <span class="share">[Share<span class="share-content">on
270 <a href="https://twitter.com/intent/tweet?text=I%27ve+completed+%22Reactor+Reboot%22+%2D+Day+22+%2D+Advent+of+Code+2021&amp;url=https%3A%2F%2Fadventofcode%2Ecom%2F2021%2Fday%2F22&amp;related=ericwastl&amp;hashtags=AdventOfCode" target="_blank">Twitter</a>
271 <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+%22Reactor+Reboot%22+%2D+Day+22+%2D+Advent+of+Code+2021+%23AdventOfCode+https%3A%2F%2Fadventofcode%2Ecom%2F2021%2Fday%2F22'}else{return false;}" target="_blank">Mastodon</a
272 ></span>]</span> this puzzle.</p>
273 </main>
274
275 <!-- ga -->
276 <script>
277 (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
278 (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
279 m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
280 })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
281 ga('create', 'UA-69522494-1', 'auto');
282 ga('set', 'anonymizeIp', true);
283 ga('send', 'pageview');
284 </script>
285 <!-- /ga -->
286 </body>
287 </html>