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 (3660B)


      1--- Day 22: Reactor Reboot ---
      2
      3Operating at these extreme ocean depths has overloaded the submarine's reactor; it needs to be
      4rebooted.
      5
      6The reactor core is made up of a large 3-dimensional grid made up entirely of cubes, one cube per
      7integer 3-dimensional coordinate (x,y,z). Each cube can be either on or off; at the start of the
      8reboot process, they are all off. (Could it be an old model of a reactor you've seen before?)
      9
     10To reboot the reactor, you just need to set all of the cubes to either on or off by following a list
     11of reboot steps (your puzzle input). Each step specifies a cuboid (the set of all cubes that have
     12coordinates which fall within ranges for x, y, and z) and whether to turn all of the cubes in that
     13cuboid on or off.
     14
     15For example, given these reboot steps:
     16
     17on x=10..12,y=10..12,z=10..12
     18on x=11..13,y=11..13,z=11..13
     19off x=9..11,y=9..11,z=9..11
     20on x=10..10,y=10..10,z=10..10
     21
     22The first step (on x=10..12,y=10..12,z=10..12) turns on a 3x3x3 cuboid consisting of 27 cubes:
     23
     24
     25 - 10,10,10
     26
     27 - 10,10,11
     28
     29 - 10,10,12
     30
     31 - 10,11,10
     32
     33 - 10,11,11
     34
     35 - 10,11,12
     36
     37 - 10,12,10
     38
     39 - 10,12,11
     40
     41 - 10,12,12
     42
     43 - 11,10,10
     44
     45 - 11,10,11
     46
     47 - 11,10,12
     48
     49 - 11,11,10
     50
     51 - 11,11,11
     52
     53 - 11,11,12
     54
     55 - 11,12,10
     56
     57 - 11,12,11
     58
     59 - 11,12,12
     60
     61 - 12,10,10
     62
     63 - 12,10,11
     64
     65 - 12,10,12
     66
     67 - 12,11,10
     68
     69 - 12,11,11
     70
     71 - 12,11,12
     72
     73 - 12,12,10
     74
     75 - 12,12,11
     76
     77 - 12,12,12
     78
     79
     80The second step (on x=11..13,y=11..13,z=11..13) turns on a 3x3x3 cuboid that overlaps with the
     81first. As a result, only 19 additional cubes turn on; the rest are already on from the previous
     82step:
     83
     84
     85 - 11,11,13
     86
     87 - 11,12,13
     88
     89 - 11,13,11
     90
     91 - 11,13,12
     92
     93 - 11,13,13
     94
     95 - 12,11,13
     96
     97 - 12,12,13
     98
     99 - 12,13,11
    100
    101 - 12,13,12
    102
    103 - 12,13,13
    104
    105 - 13,11,11
    106
    107 - 13,11,12
    108
    109 - 13,11,13
    110
    111 - 13,12,11
    112
    113 - 13,12,12
    114
    115 - 13,12,13
    116
    117 - 13,13,11
    118
    119 - 13,13,12
    120
    121 - 13,13,13
    122
    123
    124The third step (off x=9..11,y=9..11,z=9..11) turns off a 3x3x3 cuboid that overlaps partially with
    125some cubes that are on, ultimately turning off 8 cubes:
    126
    127
    128 - 10,10,10
    129
    130 - 10,10,11
    131
    132 - 10,11,10
    133
    134 - 10,11,11
    135
    136 - 11,10,10
    137
    138 - 11,10,11
    139
    140 - 11,11,10
    141
    142 - 11,11,11
    143
    144
    145The final step (on x=10..10,y=10..10,z=10..10) turns on a single cube, 10,10,10. After this last
    146step, 39 cubes are on.
    147
    148The initialization procedure only uses cubes that have x, y, and z positions of at least -50 and at
    149most 50. For now, ignore cubes outside this region.
    150
    151Here is a larger example:
    152
    153on x=-20..26,y=-36..17,z=-47..7
    154on x=-20..33,y=-21..23,z=-26..28
    155on x=-22..28,y=-29..23,z=-38..16
    156on x=-46..7,y=-6..46,z=-50..-1
    157on x=-49..1,y=-3..46,z=-24..28
    158on x=2..47,y=-22..22,z=-23..27
    159on x=-27..23,y=-28..26,z=-21..29
    160on x=-39..5,y=-6..47,z=-3..44
    161on x=-30..21,y=-8..43,z=-13..34
    162on x=-22..26,y=-27..20,z=-29..19
    163off x=-48..-32,y=26..41,z=-47..-37
    164on x=-12..35,y=6..50,z=-50..-2
    165off x=-48..-32,y=-32..-16,z=-15..-5
    166on x=-18..26,y=-33..15,z=-7..46
    167off x=-40..-22,y=-38..-28,z=23..41
    168on x=-16..35,y=-41..10,z=-47..6
    169off x=-32..-23,y=11..30,z=-14..3
    170on x=-49..-5,y=-3..45,z=-29..18
    171off x=18..30,y=-20..-8,z=-3..13
    172on x=-41..9,y=-7..43,z=-33..15
    173on x=-54112..-39298,y=-85059..-49293,z=-27449..7877
    174on x=967..23432,y=45373..81175,z=27513..53682
    175
    176The last two steps are fully outside the initialization procedure area; all other steps are fully
    177within it. After executing these steps in the initialization procedure region, 590784 cubes are
    178on.
    179
    180Execute the reboot steps. Afterward, considering only cubes in the region
    181x=-50..50,y=-50..50,z=-50..50, how many cubes are on?
    182
    183