Skip to content

Commit a4a6cf8

Browse files
committed
day 11
1 parent 21d3378 commit a4a6cf8

File tree

6 files changed

+493
-43
lines changed

6 files changed

+493
-43
lines changed

2021/Day11/README.md

Lines changed: 363 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,363 @@
1+
original source: [https://adventofcode.com/2021/day/11](https://adventofcode.com/2021/day/11)
2+
## --- Day 11: Dumbo Octopus ---
3+
You enter a large cavern full of rare bioluminescent [dumbo octopuses](https://www.youtube.com/watch?v=eih-VSaS2g0)! They seem to not like the Christmas lights on your submarine, so you turn them off for now.
4+
5+
There are 100 octopuses arranged neatly in a 10 by 10 grid. Each octopus slowly gains <em>energy</em> over time and <em>flashes</em> brightly for a moment when its energy is full. Although your lights are off, maybe you could navigate through the cave without disturbing the octopuses if you could predict when the flashes of light will happen.
6+
7+
Each octopus has an <em>energy level</em> - your submarine can remotely measure the energy level of each octopus (your puzzle input). For example:
8+
9+
<pre>
10+
<code>5483143223
11+
2745854711
12+
5264556173
13+
6141336146
14+
6357385478
15+
4167524645
16+
2176841721
17+
6882881134
18+
4846848554
19+
5283751526
20+
</code>
21+
</pre>
22+
23+
The energy level of each octopus is a value between <code>0</code> and <code>9</code>. Here, the top-left octopus has an energy level of <code>5</code>, the bottom-right one has an energy level of <code>6</code>, and so on.
24+
25+
You can model the energy levels and flashes of light in <em>steps</em>. During a single step, the following occurs:
26+
27+
28+
- First, the energy level of each octopus increases by <code>1</code>.
29+
- Then, any octopus with an energy level greater than <code>9</code> <em>flashes</em>. This increases the energy level of all adjacent octopuses by <code>1</code>, including octopuses that are diagonally adjacent. If this causes an octopus to have an energy level greater than <code>9</code>, it <em>also flashes</em>. This process continues as long as new octopuses keep having their energy level increased beyond <code>9</code>. (An octopus can only flash <em>at most once per step</em>.)
30+
- Finally, any octopus that flashed during this step has its energy level set to <code>0</code>, as it used all of its energy to flash.
31+
32+
Adjacent flashes can cause an octopus to flash on a step even if it begins that step with very little energy. Consider the middle octopus with <code>1</code> energy in this situation:
33+
34+
<pre>
35+
<code>Before any steps:
36+
11111
37+
19991
38+
19191
39+
19991
40+
11111
41+
42+
After step 1:
43+
34543
44+
4<em>000</em>4
45+
5<em>000</em>5
46+
4<em>000</em>4
47+
34543
48+
49+
After step 2:
50+
45654
51+
51115
52+
61116
53+
51115
54+
45654
55+
</code>
56+
</pre>
57+
58+
An octopus is <em>highlighted</em> when it flashed during the given step.
59+
60+
Here is how the larger example above progresses:
61+
62+
<pre>
63+
<code>Before any steps:
64+
5483143223
65+
2745854711
66+
5264556173
67+
6141336146
68+
6357385478
69+
4167524645
70+
2176841721
71+
6882881134
72+
4846848554
73+
5283751526
74+
75+
After step 1:
76+
6594254334
77+
3856965822
78+
6375667284
79+
7252447257
80+
7468496589
81+
5278635756
82+
3287952832
83+
7993992245
84+
5957959665
85+
6394862637
86+
87+
After step 2:
88+
88<em>0</em>7476555
89+
5<em>0</em>89<em>0</em>87<em>0</em>54
90+
85978896<em>0</em>8
91+
84857696<em>00</em>
92+
87<em>00</em>9<em>0</em>88<em>00</em>
93+
66<em>000</em>88989
94+
68<em>0000</em>5943
95+
<em>000000</em>7456
96+
9<em>000000</em>876
97+
87<em>0000</em>6848
98+
99+
After step 3:
100+
<em>00</em>5<em>0</em>9<em>00</em>866
101+
85<em>00</em>8<em>00</em>575
102+
99<em>000000</em>39
103+
97<em>000000</em>41
104+
9935<em>0</em>8<em>00</em>63
105+
77123<em>00000</em>
106+
791125<em>000</em>9
107+
221113<em>0000</em>
108+
<em>0</em>421125<em>000</em>
109+
<em>00</em>21119<em>000</em>
110+
111+
After step 4:
112+
2263<em>0</em>31977
113+
<em>0</em>923<em>0</em>31697
114+
<em>00</em>3222115<em>0</em>
115+
<em>00</em>41111163
116+
<em>00</em>76191174
117+
<em>00</em>53411122
118+
<em>00</em>4236112<em>0</em>
119+
5532241122
120+
1532247211
121+
113223<em>0</em>211
122+
123+
After step 5:
124+
4484144<em>000</em>
125+
2<em>0</em>44144<em>000</em>
126+
2253333493
127+
1152333274
128+
11873<em>0</em>3285
129+
1164633233
130+
1153472231
131+
6643352233
132+
2643358322
133+
2243341322
134+
135+
After step 6:
136+
5595255111
137+
3155255222
138+
33644446<em>0</em>5
139+
2263444496
140+
2298414396
141+
2275744344
142+
2264583342
143+
7754463344
144+
3754469433
145+
3354452433
146+
147+
After step 7:
148+
67<em>0</em>7366222
149+
4377366333
150+
4475555827
151+
34966557<em>0</em>9
152+
35<em>00</em>6256<em>0</em>9
153+
35<em>0</em>9955566
154+
3486694453
155+
8865585555
156+
486558<em>0</em>644
157+
4465574644
158+
159+
After step 8:
160+
7818477333
161+
5488477444
162+
5697666949
163+
46<em>0</em>876683<em>0</em>
164+
473494673<em>0</em>
165+
474<em>00</em>97688
166+
69<em>0000</em>7564
167+
<em>000000</em>9666
168+
8<em>00000</em>4755
169+
68<em>0000</em>7755
170+
171+
After step 9:
172+
9<em>0</em>6<em>0000</em>644
173+
78<em>00000</em>976
174+
69<em>000000</em>8<em>0</em>
175+
584<em>00000</em>82
176+
5858<em>0000</em>93
177+
69624<em>00000</em>
178+
8<em>0</em>2125<em>000</em>9
179+
222113<em>000</em>9
180+
9111128<em>0</em>97
181+
7911119976
182+
183+
After step 10:
184+
<em>0</em>481112976
185+
<em>00</em>31112<em>00</em>9
186+
<em>00</em>411125<em>0</em>4
187+
<em>00</em>811114<em>0</em>6
188+
<em>00</em>991113<em>0</em>6
189+
<em>00</em>93511233
190+
<em>0</em>44236113<em>0</em>
191+
553225235<em>0</em>
192+
<em>0</em>53225<em>0</em>6<em>00</em>
193+
<em>00</em>3224<em>0000</em>
194+
</code>
195+
</pre>
196+
197+
198+
After step 10, there have been a total of <code>204</code> flashes. Fast forwarding, here is the same configuration every 10 steps:
199+
200+
201+
<pre>
202+
<code>After step 20:
203+
3936556452
204+
56865568<em>0</em>6
205+
449655569<em>0</em>
206+
444865558<em>0</em>
207+
445686557<em>0</em>
208+
568<em>00</em>86577
209+
7<em>00000</em>9896
210+
<em>0000000</em>344
211+
6<em>000000</em>364
212+
46<em>0000</em>9543
213+
214+
After step 30:
215+
<em>0</em>643334118
216+
4253334611
217+
3374333458
218+
2225333337
219+
2229333338
220+
2276733333
221+
2754574565
222+
5544458511
223+
9444447111
224+
7944446119
225+
226+
After step 40:
227+
6211111981
228+
<em>0</em>421111119
229+
<em>00</em>42111115
230+
<em>000</em>3111115
231+
<em>000</em>3111116
232+
<em>00</em>65611111
233+
<em>0</em>532351111
234+
3322234597
235+
2222222976
236+
2222222762
237+
238+
After step 50:
239+
9655556447
240+
48655568<em>0</em>5
241+
448655569<em>0</em>
242+
445865558<em>0</em>
243+
457486557<em>0</em>
244+
57<em>000</em>86566
245+
6<em>00000</em>9887
246+
8<em>000000</em>533
247+
68<em>00000</em>633
248+
568<em>0000</em>538
249+
250+
After step 60:
251+
25333342<em>00</em>
252+
274333464<em>0</em>
253+
2264333458
254+
2225333337
255+
2225333338
256+
2287833333
257+
3854573455
258+
1854458611
259+
1175447111
260+
1115446111
261+
262+
After step 70:
263+
8211111164
264+
<em>0</em>421111166
265+
<em>00</em>42111114
266+
<em>000</em>4211115
267+
<em>0000</em>211116
268+
<em>00</em>65611111
269+
<em>0</em>532351111
270+
7322235117
271+
5722223475
272+
4572222754
273+
274+
After step 80:
275+
1755555697
276+
59655556<em>0</em>9
277+
448655568<em>0</em>
278+
445865558<em>0</em>
279+
457<em>0</em>86557<em>0</em>
280+
57<em>000</em>86566
281+
7<em>00000</em>8666
282+
<em>0000000</em>99<em>0</em>
283+
<em>0000000</em>8<em>00</em>
284+
<em>0000000000</em>
285+
286+
After step 90:
287+
7433333522
288+
2643333522
289+
2264333458
290+
2226433337
291+
2222433338
292+
2287833333
293+
2854573333
294+
4854458333
295+
3387779333
296+
3333333333
297+
298+
After step 100:
299+
<em>0</em>397666866
300+
<em>0</em>749766918
301+
<em>00</em>53976933
302+
<em>000</em>4297822
303+
<em>000</em>4229892
304+
<em>00</em>53222877
305+
<em>0</em>532222966
306+
9322228966
307+
7922286866
308+
6789998766
309+
</code>
310+
</pre>
311+
312+
After 100 steps, there have been a total of <code><em>1656</em></code> flashes.
313+
314+
Given the starting energy levels of the dumbo octopuses in your cavern, simulate 100 steps. <em>How many total flashes are there after 100 steps?</em>
315+
316+
317+
## --- Part Two ---
318+
It seems like the individual flashes aren't bright enough to navigate. However, you might have a better option: the flashes seem to be <em>synchronizing</em>!
319+
320+
In the example above, the first time all octopuses flash simultaneously is step <code><em>195</em></code>:
321+
322+
<pre>
323+
<code>After step 193:
324+
5877777777
325+
8877777777
326+
7777777777
327+
7777777777
328+
7777777777
329+
7777777777
330+
7777777777
331+
7777777777
332+
7777777777
333+
7777777777
334+
335+
After step 194:
336+
6988888888
337+
9988888888
338+
8888888888
339+
8888888888
340+
8888888888
341+
8888888888
342+
8888888888
343+
8888888888
344+
8888888888
345+
8888888888
346+
347+
After step 195:
348+
<em>0000000000</em>
349+
<em>0000000000</em>
350+
<em>0000000000</em>
351+
<em>0000000000</em>
352+
<em>0000000000</em>
353+
<em>0000000000</em>
354+
<em>0000000000</em>
355+
<em>0000000000</em>
356+
<em>0000000000</em>
357+
<em>0000000000</em>
358+
</code>
359+
</pre>
360+
361+
If you can calculate the exact moments when the octopuses will all flash simultaneously, you should be able to navigate through the cavern. <em>What is the first step during which all octopuses flash?</em>
362+
363+

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy