aoc-2021-rust

Advent of Code 2021 Solutions in Rust
git clone https://git.sinitax.com/sinitax/aoc-2021-rust
Log | Files | Refs | README | sfeed.txt

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
      7energy over time and flashes 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 energy level - 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 steps. 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 flashes. 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 also flashes. This process continues as long as
     37new octopuses keep having their energy level increased beyond 9. (An octopus can only flash
     38at most once per step.)
     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
     5640004
     5750005
     5840004
     5934543
     60
     61After step 2:
     6245654
     6351115
     6461116
     6551115
     6645654
     67
     68An octopus is highlighted 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:
     978807476555
     985089087054
     998597889608
    1008485769600
    1018700908800
    1026600088989
    1036800005943
    1040000007456
    1059000000876
    1068700006848
    107
    108After step 3:
    1090050900866
    1108500800575
    1119900000039
    1129700000041
    1139935080063
    1147712300000
    1157911250009
    1162211130000
    1170421125000
    1180021119000
    119
    120After step 4:
    1212263031977
    1220923031697
    1230032221150
    1240041111163
    1250076191174
    1260053411122
    1270042361120
    1285532241122
    1291532247211
    1301132230211
    131
    132After step 5:
    1334484144000
    1342044144000
    1352253333493
    1361152333274
    1371187303285
    1381164633233
    1391153472231
    1406643352233
    1412643358322
    1422243341322
    143
    144After step 6:
    1455595255111
    1463155255222
    1473364444605
    1482263444496
    1492298414396
    1502275744344
    1512264583342
    1527754463344
    1533754469433
    1543354452433
    155
    156After step 7:
    1576707366222
    1584377366333
    1594475555827
    1603496655709
    1613500625609
    1623509955566
    1633486694453
    1648865585555
    1654865580644
    1664465574644
    167
    168After step 8:
    1697818477333
    1705488477444
    1715697666949
    1724608766830
    1734734946730
    1744740097688
    1756900007564
    1760000009666
    1778000004755
    1786800007755
    179
    180After step 9:
    1819060000644
    1827800000976
    1836900000080
    1845840000082
    1855858000093
    1866962400000
    1878021250009
    1882221130009
    1899111128097
    1907911119976
    191
    192After step 10:
    1930481112976
    1940031112009
    1950041112504
    1960081111406
    1970099111306
    1980093511233
    1990442361130
    2005532252350
    2010532250600
    2020032240000
    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
    2095686556806
    2104496555690
    2114448655580
    2124456865570
    2135680086577
    2147000009896
    2150000000344
    2166000000364
    2174600009543
    218
    219After step 30:
    2200643334118
    2214253334611
    2223374333458
    2232225333337
    2242229333338
    2252276733333
    2262754574565
    2275544458511
    2289444447111
    2297944446119
    230
    231After step 40:
    2326211111981
    2330421111119
    2340042111115
    2350003111115
    2360003111116
    2370065611111
    2380532351111
    2393322234597
    2402222222976
    2412222222762
    242
    243After step 50:
    2449655556447
    2454865556805
    2464486555690
    2474458655580
    2484574865570
    2495700086566
    2506000009887
    2518000000533
    2526800000633
    2535680000538
    254
    255After step 60:
    2562533334200
    2572743334640
    2582264333458
    2592225333337
    2602225333338
    2612287833333
    2623854573455
    2631854458611
    2641175447111
    2651115446111
    266
    267After step 70:
    2688211111164
    2690421111166
    2700042111114
    2710004211115
    2720000211116
    2730065611111
    2740532351111
    2757322235117
    2765722223475
    2774572222754
    278
    279After step 80:
    2801755555697
    2815965555609
    2824486555680
    2834458655580
    2844570865570
    2855700086566
    2867000008666
    2870000000990
    2880000000800
    2890000000000
    290
    291After step 90:
    2927433333522
    2932643333522
    2942264333458
    2952226433337
    2962222433338
    2972287833333
    2982854573333
    2994854458333
    3003387779333
    3013333333333
    302
    303After step 100:
    3040397666866
    3050749766918
    3060053976933
    3070004297822
    3080004229892
    3090053222877
    3100532222966
    3119322228966
    3127922286866
    3136789998766
    314
    315After 100 steps, there have been a total of 1656 flashes.
    316
    317Given the starting energy levels of the dumbo octopuses in your cavern, simulate 100 steps.
    318How many total flashes are there after 100 steps?
    319
    320