part1 (6934B)
1--- Day 11: Dumbo Octopus --- 2 3You enter a large cavern full of rare bioluminescent dumbo octopuses! They seem to not like the 4Christmas lights on your submarine, so you turn them off for now. 5 6There are 100 octopuses arranged neatly in a 10 by 10 grid. Each octopus slowly gains 7[1m[37menergy[0m over time and [1m[37mflashes[0m brightly for a moment when its energy is full. Although your lights are 8off, maybe you could navigate through the cave without disturbing the octopuses if you could predict 9when the flashes of light will happen. 10 11Each octopus has an [1m[37menergy level[0m - your submarine can remotely measure the energy level of each 12octopus (your puzzle input). For example: 13 145483143223 152745854711 165264556173 176141336146 186357385478 194167524645 202176841721 216882881134 224846848554 235283751526 24 25The energy level of each octopus is a value between 0 and 9. Here, the top-left octopus has an 26energy level of 5, the bottom-right one has an energy level of 6, and so on. 27 28You can model the energy levels and flashes of light in [1m[37msteps[0m. During a single step, the following 29occurs: 30 31 32 - First, the energy level of each octopus increases by 1. 33 34 - Then, any octopus with an energy level greater than 9 [1m[37mflashes[0m. This increases the energy level of 35all adjacent octopuses by 1, including octopuses that are diagonally adjacent. If this causes an 36octopus to have an energy level greater than 9, it [1m[37malso flashes[0m. This process continues as long as 37new octopuses keep having their energy level increased beyond 9. (An octopus can only flash 38[1m[37mat most once per step[0m.) 39 40 - Finally, any octopus that flashed during this step has its energy level set to 0, as it used all 41of its energy to flash. 42 43 44Adjacent flashes can cause an octopus to flash on a step even if it begins that step with very 45little energy. Consider the middle octopus with 1 energy in this situation: 46 47Before any steps: 4811111 4919991 5019191 5119991 5211111 53 54After step 1: 5534543 564[1m[37m000[0m4 575[1m[37m000[0m5 584[1m[37m000[0m4 5934543 60 61After step 2: 6245654 6351115 6461116 6551115 6645654 67 68An octopus is [1m[37mhighlighted[0m when it flashed during the given step. 69 70Here is how the larger example above progresses: 71 72Before any steps: 735483143223 742745854711 755264556173 766141336146 776357385478 784167524645 792176841721 806882881134 814846848554 825283751526 83 84After step 1: 856594254334 863856965822 876375667284 887252447257 897468496589 905278635756 913287952832 927993992245 935957959665 946394862637 95 96After step 2: 9788[1m[37m0[0m7476555 985[1m[37m0[0m89[1m[37m0[0m87[1m[37m0[0m54 9985978896[1m[37m0[0m8 10084857696[1m[37m00[0m 10187[1m[37m00[0m9[1m[37m0[0m88[1m[37m00[0m 10266[1m[37m000[0m88989 10368[1m[37m0000[0m5943 104[1m[37m000000[0m7456 1059[1m[37m000000[0m876 10687[1m[37m0000[0m6848 107 108After step 3: 109[1m[37m00[0m5[1m[37m0[0m9[1m[37m00[0m866 11085[1m[37m00[0m8[1m[37m00[0m575 11199[1m[37m000000[0m39 11297[1m[37m000000[0m41 1139935[1m[37m0[0m8[1m[37m00[0m63 11477123[1m[37m00000[0m 115791125[1m[37m000[0m9 116221113[1m[37m0000[0m 117[1m[37m0[0m421125[1m[37m000[0m 118[1m[37m00[0m21119[1m[37m000[0m 119 120After step 4: 1212263[1m[37m0[0m31977 122[1m[37m0[0m923[1m[37m0[0m31697 123[1m[37m00[0m3222115[1m[37m0[0m 124[1m[37m00[0m41111163 125[1m[37m00[0m76191174 126[1m[37m00[0m53411122 127[1m[37m00[0m4236112[1m[37m0[0m 1285532241122 1291532247211 130113223[1m[37m0[0m211 131 132After step 5: 1334484144[1m[37m000[0m 1342[1m[37m0[0m44144[1m[37m000[0m 1352253333493 1361152333274 13711873[1m[37m0[0m3285 1381164633233 1391153472231 1406643352233 1412643358322 1422243341322 143 144After step 6: 1455595255111 1463155255222 14733644446[1m[37m0[0m5 1482263444496 1492298414396 1502275744344 1512264583342 1527754463344 1533754469433 1543354452433 155 156After step 7: 15767[1m[37m0[0m7366222 1584377366333 1594475555827 16034966557[1m[37m0[0m9 16135[1m[37m00[0m6256[1m[37m0[0m9 16235[1m[37m0[0m9955566 1633486694453 1648865585555 165486558[1m[37m0[0m644 1664465574644 167 168After step 8: 1697818477333 1705488477444 1715697666949 17246[1m[37m0[0m876683[1m[37m0[0m 173473494673[1m[37m0[0m 174474[1m[37m00[0m97688 17569[1m[37m0000[0m7564 176[1m[37m000000[0m9666 1778[1m[37m00000[0m4755 17868[1m[37m0000[0m7755 179 180After step 9: 1819[1m[37m0[0m6[1m[37m0000[0m644 18278[1m[37m00000[0m976 18369[1m[37m000000[0m8[1m[37m0[0m 184584[1m[37m00000[0m82 1855858[1m[37m0000[0m93 18669624[1m[37m00000[0m 1878[1m[37m0[0m2125[1m[37m000[0m9 188222113[1m[37m000[0m9 1899111128[1m[37m0[0m97 1907911119976 191 192After step 10: 193[1m[37m0[0m481112976 194[1m[37m00[0m31112[1m[37m00[0m9 195[1m[37m00[0m411125[1m[37m0[0m4 196[1m[37m00[0m811114[1m[37m0[0m6 197[1m[37m00[0m991113[1m[37m0[0m6 198[1m[37m00[0m93511233 199[1m[37m0[0m44236113[1m[37m0[0m 200553225235[1m[37m0[0m 201[1m[37m0[0m53225[1m[37m0[0m6[1m[37m00[0m 202[1m[37m00[0m3224[1m[37m0000[0m 203 204After step 10, there have been a total of 204 flashes. Fast forwarding, here is the same 205configuration every 10 steps: 206 207After step 20: 2083936556452 20956865568[1m[37m0[0m6 210449655569[1m[37m0[0m 211444865558[1m[37m0[0m 212445686557[1m[37m0[0m 213568[1m[37m00[0m86577 2147[1m[37m00000[0m9896 215[1m[37m0000000[0m344 2166[1m[37m000000[0m364 21746[1m[37m0000[0m9543 218 219After step 30: 220[1m[37m0[0m643334118 2214253334611 2223374333458 2232225333337 2242229333338 2252276733333 2262754574565 2275544458511 2289444447111 2297944446119 230 231After step 40: 2326211111981 233[1m[37m0[0m421111119 234[1m[37m00[0m42111115 235[1m[37m000[0m3111115 236[1m[37m000[0m3111116 237[1m[37m00[0m65611111 238[1m[37m0[0m532351111 2393322234597 2402222222976 2412222222762 242 243After step 50: 2449655556447 24548655568[1m[37m0[0m5 246448655569[1m[37m0[0m 247445865558[1m[37m0[0m 248457486557[1m[37m0[0m 24957[1m[37m000[0m86566 2506[1m[37m00000[0m9887 2518[1m[37m000000[0m533 25268[1m[37m00000[0m633 253568[1m[37m0000[0m538 254 255After step 60: 25625333342[1m[37m00[0m 257274333464[1m[37m0[0m 2582264333458 2592225333337 2602225333338 2612287833333 2623854573455 2631854458611 2641175447111 2651115446111 266 267After step 70: 2688211111164 269[1m[37m0[0m421111166 270[1m[37m00[0m42111114 271[1m[37m000[0m4211115 272[1m[37m0000[0m211116 273[1m[37m00[0m65611111 274[1m[37m0[0m532351111 2757322235117 2765722223475 2774572222754 278 279After step 80: 2801755555697 28159655556[1m[37m0[0m9 282448655568[1m[37m0[0m 283445865558[1m[37m0[0m 284457[1m[37m0[0m86557[1m[37m0[0m 28557[1m[37m000[0m86566 2867[1m[37m00000[0m8666 287[1m[37m0000000[0m99[1m[37m0[0m 288[1m[37m0000000[0m8[1m[37m00[0m 289[1m[37m0000000000[0m 290 291After step 90: 2927433333522 2932643333522 2942264333458 2952226433337 2962222433338 2972287833333 2982854573333 2994854458333 3003387779333 3013333333333 302 303After step 100: 304[1m[37m0[0m397666866 305[1m[37m0[0m749766918 306[1m[37m00[0m53976933 307[1m[37m000[0m4297822 308[1m[37m000[0m4229892 309[1m[37m00[0m53222877 310[1m[37m0[0m532222966 3119322228966 3127922286866 3136789998766 314 315After 100 steps, there have been a total of [1m[37m1656[0m flashes. 316 317Given the starting energy levels of the dumbo octopuses in your cavern, simulate 100 steps. 318[1m[37mHow many total flashes are there after 100 steps?[0m 319 320