4 <meta charset=
"utf-8"/>
5 <title>Day
23 - 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>
17 Oh, hello! Funny seeing you here.
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.
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.
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
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!
36 If you'd like to hang out, I'm @ericwastl on Twitter.
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">46*
</span></div></div><div><h1 class=
"title-event"> <span class=
"title-event-wrap">λ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>
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://kotlinlang.org/" target=
"_blank" onclick=
"if(ga)ga('send','event','sponsor','sidebar',this.href);" rel=
"noopener">Kotlin by JetBrains
</a> - Trees, lists, packages - it
's Advent of Code time! Get ready to solve puzzles in Kotlin. Watch us livestream our discussions about the solutions for the first few puzzles, join our leaderboard, win prizes. Happy holidays!
</div></div>
98 <article class=
"day-desc"><h2>--- Day
23: Unstable Diffusion ---
</h2><p>You enter a large crater of gray dirt where the grove is supposed to be. All around you, plants you imagine were expected to be full of fruit are instead withered and broken. A large group of Elves has formed in the middle of the grove.
</p>
99 <p>"...but this volcano has been dormant for months. Without ash, the fruit can't grow!"</p>
100 <p>You look up to see a massive, snow-capped mountain towering above you.
</p>
101 <p>"It's not like there are other active volcanoes here; we've looked everywhere."</p>
102 <p>"But our scanners show active magma flows; clearly it's going <em>somewhere</em>."</p>
103 <p>They finally notice you at the edge of the grove, your pack almost overflowing from the random
<em class=
"star">star
</em> fruit you've been collecting. Behind you, elephants and monkeys explore the grove, looking concerned. Then, the Elves recognize the ash cloud slowly spreading above your recent detour.
</p>
104 <p>"Why do you--" "How is--" "Did you just--"</p>
105 <p>Before any of them can form a complete question, another Elf speaks up:
"Okay, new plan. We have almost enough fruit already, and ash from the plume should spread here eventually. If we quickly plant new seedlings now, we can still make it to the extraction point. Spread out!"</p>
106 <p>The Elves each reach into their pack and pull out a tiny plant. The plants rely on important nutrients from the ash, so they can't be planted too close together.
</p>
107 <p>There isn't enough time to let the Elves figure out where to plant the seedlings themselves; you quickly scan the grove (your puzzle input) and note their positions.
</p>
117 <p>The scan shows Elves
<code>#
</code> and empty ground
<code>.
</code>; outside your scan, more empty ground extends a long way in every direction. The scan is oriented so that
<em>north is up
</em>; orthogonal directions are written N (north), S (south), W (west), and E (east), while diagonal directions are written NE, NW, SE, SW.
</p>
118 <p>The Elves follow a time-consuming process to figure out where they should each go; you can speed up this process considerably. The process consists of some number of
<em>rounds
</em> during which Elves alternate between considering where to move and actually moving.
</p>
119 <p>During the
<em>first half
</em> of each round, each Elf considers the eight positions adjacent to themself. If no other Elves are in one of those eight positions, the Elf
<em>does not do anything
</em> during this round. Otherwise, the Elf looks in each of four directions in the following order and
<em>proposes
</em> moving one step in the
<em>first valid direction
</em>:
</p>
121 <li>If there is no Elf in the N, NE, or NW adjacent positions, the Elf proposes moving
<em>north
</em> one step.
</li>
122 <li>If there is no Elf in the S, SE, or SW adjacent positions, the Elf proposes moving
<em>south
</em> one step.
</li>
123 <li>If there is no Elf in the W, NW, or SW adjacent positions, the Elf proposes moving
<em>west
</em> one step.
</li>
124 <li>If there is no Elf in the E, NE, or SE adjacent positions, the Elf proposes moving
<em>east
</em> one step.
</li>
126 <p>After each Elf has had a chance to propose a move, the
<em>second half
</em> of the round can begin. Simultaneously, each Elf moves to their proposed destination tile if they were the
<em>only
</em> Elf to propose moving to that position. If two or more Elves propose moving to the same position,
<em>none
</em> of those Elves move.
</p>
127 <p>Finally, at the end of the round, the
<em>first direction
</em> the Elves considered is moved to the end of the list of directions. For example, during the second round, the Elves would try proposing a move to the south first, then west, then east, then north. On the third round, the Elves would first consider west, then east, then north, then south.
</p>
128 <p>As a smaller example, consider just these five Elves:
</p>
136 <p>The northernmost two Elves and southernmost two Elves all propose moving north, while the middle Elf cannot move north and proposes moving south. The middle Elf proposes the same destination as the southwest Elf, so neither of them move, but the other three do:
</p>
144 <p>Next, the northernmost two Elves and the southernmost Elf all propose moving south. Of the remaining middle two Elves, the west one cannot move south and proposes moving west, while the east one cannot move south
<em>or
</em> west and proposes moving east. All five Elves succeed in moving to their proposed positions:
</p>
152 <p>Finally, the southernmost two Elves choose not to move at all. Of the remaining three Elves, the west one proposes moving west, the east one proposes moving east, and the middle one proposes moving north; all three succeed in moving:
</p>
160 <p>At this point, no Elves need to move, and so the process ends.
</p>
161 <p>The larger example above proceeds as follows:
</p>
162 <pre><code>== Initial State ==
246 <p>After a few more rounds...
</p>
247 <pre><code>== End of Round
10 ==
261 <p>To make sure they're on the right track, the Elves like to check after round
10 that they're making good progress toward covering enough ground. To do this, count the number of empty ground tiles contained by the smallest rectangle that contains every Elf. (The edges of the rectangle should be aligned to the N/S/E/W directions; the Elves do not have the patience to calculate
<span title=
"Arbitrary Rectangles is my Piet Mondrian cover band.">arbitrary rectangles
</span>.) In the above example, that rectangle is:
</p>
262 <pre><code>......#.....
274 <p>In this region, the number of empty ground tiles is
<code><em>110</em></code>.
</p>
275 <p>Simulate the Elves' process and find the smallest rectangle that contains the Elves after
10 rounds.
<em>How many empty ground tiles does that rectangle contain?
</em></p>
277 <p>Your puzzle answer was
<code>4236</code>.
</p><article class=
"day-desc"><h2 id=
"part2">--- Part Two ---
</h2><p>It seems you're on the right track. Finish simulating the process and figure out where the Elves need to go. How many rounds did you save them?
</p>
278 <p>In the example above, the
<em>first round where no Elf moved
</em> was round
<code><em>20</em></code>:
</p>
279 <pre><code>.......#......
292 <p>Figure out where the Elves need to go.
<em>What is the number of the first round where no Elf moves?
</em></p>
294 <p>Your puzzle answer was
<code>1023</code>.
</p><p class=
"day-success">Both parts of this puzzle are complete! They provide two gold stars: **
</p>
295 <p>At this point, you should
<a href=
"/2022">return to your Advent calendar
</a> and try another puzzle.
</p>
296 <p>If you still want to see it, you can
<a href=
"23/input" target=
"_blank">get your puzzle input
</a>.
</p>
297 <p>You can also
<span class=
"share">[Share
<span class=
"share-content">on
298 <a href=
"https://twitter.com/intent/tweet?text=I%27ve+completed+%22Unstable+Diffusion%22+%2D+Day+23+%2D+Advent+of+Code+2022&url=https%3A%2F%2Fadventofcode%2Ecom%2F2022%2Fday%2F23&related=ericwastl&hashtags=AdventOfCode" target=
"_blank">Twitter
</a>
299 <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+%22Unstable+Diffusion%22+%2D+Day+23+%2D+Advent+of+Code+2022+%23AdventOfCode+https%3A%2F%2Fadventofcode%2Ecom%2F2022%2Fday%2F23'}else{return false;}" target=
"_blank">Mastodon
</a
300 ></span>]
</span> this puzzle.
</p>
305 (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
306 (i[r].q=i[r].q||[]).push(arguments)},i[r].l=
1*new Date();a=s.createElement(o),
307 m=s.getElementsByTagName(o)[
0];a.async=
1;a.src=g;m.parentNode.insertBefore(a,m)
308 })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
309 ga('create', 'UA-
69522494-
1', 'auto');
310 ga('set', 'anonymizeIp', true);
311 ga('send', 'pageview');