Bit more tidying
[advent-of-code-20.git] / problems / day11.html
1 <!DOCTYPE html>
2 <html lang="en-us">
3 <head>
4 <meta charset="utf-8"/>
5 <title>Day 11 - 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">22*</span></div></div><div><h1 class="title-event">&nbsp;&nbsp;&nbsp;<span class="title-event-wrap">int y=</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://www.twilio.com/quest?utm_source=advent-of-code-20&amp;utm_medium=website" 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 11: Seating System ---</h2><p>Your plane lands with plenty of time to spare. The final leg of your journey is a ferry that goes directly to the tropical island where you can finally start your vacation. As you reach the waiting area to board the ferry, you realize you're so early, nobody else has even arrived yet!</p>
99 <p>By modeling the process people use to choose (or abandon) their seat in the waiting area, you're pretty sure you can predict the best place to sit. You make a quick map of the seat layout (your puzzle input).</p>
100 <p>The seat layout fits neatly on a grid. Each position is either floor (<code>.</code>), an empty seat (<code>L</code>), or an occupied seat (<code>#</code>). For example, the initial seat layout might look like this:</p>
101 <pre><code>L.LL.LL.LL
102 LLLLLLL.LL
103 L.L.L..L..
104 LLLL.LL.LL
105 L.LL.LL.LL
106 L.LLLLL.LL
107 ..L.L.....
108 LLLLLLLLLL
109 L.LLLLLL.L
110 L.LLLLL.LL
111 </code></pre>
112 <p>Now, you just need to model the people who will be arriving shortly. Fortunately, people are entirely predictable and always follow a simple set of rules. All decisions are based on the <em>number of occupied seats</em> adjacent to a given seat (one of the eight positions immediately up, down, left, right, or diagonal from the seat). The following rules are applied to every seat simultaneously:</p>
113 <ul>
114 <li>If a seat is <em>empty</em> (<code>L</code>) and there are <em>no</em> occupied seats adjacent to it, the seat becomes <em>occupied</em>.</li>
115 <li>If a seat is <em>occupied</em> (<code>#</code>) and <em>four or more</em> seats adjacent to it are also occupied, the seat becomes <em>empty</em>.</li>
116 <li>Otherwise, the seat's state does not change.</li>
117 </ul>
118 <p><span title="Floor... floor never changes.">Floor (<code>.</code>) never changes</span>; seats don't move, and nobody sits on the floor.</p>
119 <p>After one round of these rules, every seat in the example layout becomes occupied:</p>
120 <pre><code>#.##.##.##
121 #######.##
122 #.#.#..#..
123 ####.##.##
124 #.##.##.##
125 #.#####.##
126 ..#.#.....
127 ##########
128 #.######.#
129 #.#####.##
130 </code></pre>
131 <p>After a second round, the seats with four or more occupied adjacent seats become empty again:</p>
132 <pre><code>#.LL.L#.##
133 #LLLLLL.L#
134 L.L.L..L..
135 #LLL.LL.L#
136 #.LL.LL.LL
137 #.LLLL#.##
138 ..L.L.....
139 #LLLLLLLL#
140 #.LLLLLL.L
141 #.#LLLL.##
142 </code></pre>
143 <p>This process continues for three more rounds:</p>
144 <pre><code>#.##.L#.##
145 #L###LL.L#
146 L.#.#..#..
147 #L##.##.L#
148 #.##.LL.LL
149 #.###L#.##
150 ..#.#.....
151 #L######L#
152 #.LL###L.L
153 #.#L###.##
154 </code></pre>
155 <pre><code>#.#L.L#.##
156 #LLL#LL.L#
157 L.L.L..#..
158 #LLL.##.L#
159 #.LL.LL.LL
160 #.LL#L#.##
161 ..L.L.....
162 #L#LLLL#L#
163 #.LLLLLL.L
164 #.#L#L#.##
165 </code></pre>
166 <pre><code>#.#L.L#.##
167 #LLL#LL.L#
168 L.#.L..#..
169 #L##.##.L#
170 #.#L.LL.LL
171 #.#L#L#.##
172 ..L.L.....
173 #L#L##L#L#
174 #.LLLLLL.L
175 #.#L#L#.##
176 </code></pre>
177 <p>At this point, something interesting happens: the chaos stabilizes and further applications of these rules cause no seats to change state! Once people stop moving around, you count <em><code>37</code></em> occupied seats.</p>
178 <p>Simulate your seating area by applying the seating rules repeatedly until no seats change state. <em>How many seats end up occupied?</em></p>
179 </article>
180 <p>Your puzzle answer was <code>2270</code>.</p><article class="day-desc"><h2 id="part2">--- Part Two ---</h2><p>As soon as people start to arrive, you realize your mistake. People don't just care about adjacent seats - they care about <em>the first seat they can see</em> in each of those eight directions!</p>
181 <p>Now, instead of considering just the eight immediately adjacent seats, consider the <em>first seat</em> in each of those eight directions. For example, the empty seat below would see <em>eight</em> occupied seats:</p>
182 <pre><code>.......#.
183 ...#.....
184 .#.......
185 .........
186 ..#L....#
187 ....#....
188 .........
189 #........
190 ...#.....
191 </code></pre>
192 <p>The leftmost empty seat below would only see <em>one</em> empty seat, but cannot see any of the occupied ones:</p>
193 <pre><code>.............
194 .L.L.#.#.#.#.
195 .............
196 </code></pre>
197 <p>The empty seat below would see <em>no</em> occupied seats:</p>
198 <pre><code>.##.##.
199 #.#.#.#
200 ##...##
201 ...L...
202 ##...##
203 #.#.#.#
204 .##.##.
205 </code></pre>
206 <p>Also, people seem to be more tolerant than you expected: it now takes <em>five or more</em> visible occupied seats for an occupied seat to become empty (rather than <em>four or more</em> from the previous rules). The other rules still apply: empty seats that see no occupied seats become occupied, seats matching no rule don't change, and floor never changes.</p>
207 <p>Given the same starting layout as above, these new rules cause the seating area to shift around as follows:</p>
208 <pre><code>L.LL.LL.LL
209 LLLLLLL.LL
210 L.L.L..L..
211 LLLL.LL.LL
212 L.LL.LL.LL
213 L.LLLLL.LL
214 ..L.L.....
215 LLLLLLLLLL
216 L.LLLLLL.L
217 L.LLLLL.LL
218 </code></pre>
219 <pre><code>#.##.##.##
220 #######.##
221 #.#.#..#..
222 ####.##.##
223 #.##.##.##
224 #.#####.##
225 ..#.#.....
226 ##########
227 #.######.#
228 #.#####.##
229 </code></pre>
230 <pre><code>#.LL.LL.L#
231 #LLLLLL.LL
232 L.L.L..L..
233 LLLL.LL.LL
234 L.LL.LL.LL
235 L.LLLLL.LL
236 ..L.L.....
237 LLLLLLLLL#
238 #.LLLLLL.L
239 #.LLLLL.L#
240 </code></pre>
241 <pre><code>#.L#.##.L#
242 #L#####.LL
243 L.#.#..#..
244 ##L#.##.##
245 #.##.#L.##
246 #.#####.#L
247 ..#.#.....
248 LLL####LL#
249 #.L#####.L
250 #.L####.L#
251 </code></pre>
252 <pre><code>#.L#.L#.L#
253 #LLLLLL.LL
254 L.L.L..#..
255 ##LL.LL.L#
256 L.LL.LL.L#
257 #.LLLLL.LL
258 ..L.L.....
259 LLLLLLLLL#
260 #.LLLLL#.L
261 #.L#LL#.L#
262 </code></pre>
263 <pre><code>#.L#.L#.L#
264 #LLLLLL.LL
265 L.L.L..#..
266 ##L#.#L.L#
267 L.L#.#L.L#
268 #.L####.LL
269 ..#.#.....
270 LLL###LLL#
271 #.LLLLL#.L
272 #.L#LL#.L#
273 </code></pre>
274 <pre><code>#.L#.L#.L#
275 #LLLLLL.LL
276 L.L.L..#..
277 ##L#.#L.L#
278 L.L#.LL.L#
279 #.LLLL#.LL
280 ..#.L.....
281 LLL###LLL#
282 #.LLLLL#.L
283 #.L#LL#.L#
284 </code></pre>
285 <p>Again, at this point, people stop shifting around and the seating area reaches equilibrium. Once this occurs, you count <em><code>26</code></em> occupied seats.</p>
286 <p>Given the new visibility method and the rule change for occupied seats becoming empty, once equilibrium is reached, <em>how many seats end up occupied?</em></p>
287 </article>
288 <p>Your puzzle answer was <code>2042</code>.</p><p class="day-success">Both parts of this puzzle are complete! They provide two gold stars: **</p>
289 <p>At this point, you should <a href="/2020">return to your Advent calendar</a> and try another puzzle.</p>
290 <p>If you still want to see it, you can <a href="11/input" target="_blank">get your puzzle input</a>.</p>
291 <p>You can also <span class="share">[Share<span class="share-content">on
292 <a href="https://twitter.com/intent/tweet?text=I%27ve+completed+%22Seating+System%22+%2D+Day+11+%2D+Advent+of+Code+2020&amp;url=https%3A%2F%2Fadventofcode%2Ecom%2F2020%2Fday%2F11&amp;related=ericwastl&amp;hashtags=AdventOfCode" target="_blank">Twitter</a>
293 <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+%22Seating+System%22+%2D+Day+11+%2D+Advent+of+Code+2020+%23AdventOfCode+https%3A%2F%2Fadventofcode%2Ecom%2F2020%2Fday%2F11'}else{return false;}" target="_blank">Mastodon</a
294 ></span>]</span> this puzzle.</p>
295 </main>
296
297 <!-- ga -->
298 <script>
299 (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
300 (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
301 m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
302 })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
303 ga('create', 'UA-69522494-1', 'auto');
304 ga('set', 'anonymizeIp', true);
305 ga('send', 'pageview');
306 </script>
307 <!-- /ga -->
308 </body>
309 </html>