part1 (3416B)
1--- Day 17: Conway Cubes --- 2 3As your flight slowly drifts through the sky, the Elves at the Mythical Information Bureau at the 4North Pole contact you. They'd like some help debugging a malfunctioning experimental energy source 5aboard one of their super-secret imaging satellites. 6 7The experimental energy source is based on cutting-edge technology: a set of Conway Cubes contained 8in a pocket dimension! When you hear it's having problems, you can't help but agree to take a look. 9 10The pocket dimension contains an infinite 3-dimensional grid. At every integer 3-dimensional 11coordinate (x,y,z), there exists a single cube which is either [1m[37mactive[0m or 12[1m[37minactive[0m. 13 14In the initial state of the pocket dimension, almost all cubes start [1m[37minactive[0m. The only 15exception to this is a small flat region of cubes (your puzzle input); the cubes in this region 16start in the specified [1m[37mactive[0m (#) or [1m[37minactive[0m (.) state. 17 18The energy source then proceeds to boot up by executing six [1m[37mcycles[0m. 19 20Each cube only ever considers its [1m[37mneighbors[0m: any of the 26 other cubes where any of 21their coordinates differ by at most 1. For example, given the cube at x=1,y=2,z=3, its neighbors 22include the cube at x=2,y=2,z=2, the cube at x=0,y=2,z=3, and so on. 23 24During a cycle, [1m[37mall[0m cubes [1m[37msimultaneously[0m change their state according to 25the following rules: 26 27 28 - If a cube is [1m[37mactive[0m and [1m[37mexactly 2 or 3[0m of its neighbors are also 29active, the cube remains [1m[37mactive[0m. Otherwise, the cube becomes [1m[37minactive[0m. 30 - If a cube is [1m[37minactive[0m but [1m[37mexactly 3[0m of its neighbors are active, the 31cube becomes [1m[37mactive[0m. Otherwise, the cube remains [1m[37minactive[0m. 32 33 34The engineers responsible for this experimental energy source would like you to simulate the pocket 35dimension and determine what the configuration of cubes should be at the end of the six-cycle boot 36process. 37 38For example, consider the following initial state: 39 40.#. 41..# 42### 43 44Even though the pocket dimension is 3-dimensional, this initial state represents a small 452-dimensional slice of it. (In particular, this initial state defines a 3x3x1 region of the 463-dimensional space.) 47 48Simulating a few cycles from this initial state produces the following configurations, where the 49result of each cycle is shown layer-by-layer at each given z coordinate (and the frame of view 50follows the active cells in each cycle): 51 52Before any cycles: 53 54z=0 55.#. 56..# 57### 58 59 60After 1 cycle: 61 62z=-1 63#.. 64..# 65.#. 66 67z=0 68#.# 69.## 70.#. 71 72z=1 73#.. 74..# 75.#. 76 77 78After 2 cycles: 79 80z=-2 81..... 82..... 83..#.. 84..... 85..... 86 87z=-1 88..#.. 89.#..# 90....# 91.#... 92..... 93 94z=0 95##... 96##... 97#.... 98....# 99.###. 100 101z=1 102..#.. 103.#..# 104....# 105.#... 106..... 107 108z=2 109..... 110..... 111..#.. 112..... 113..... 114 115 116After 3 cycles: 117 118z=-2 119....... 120....... 121..##... 122..###.. 123....... 124....... 125....... 126 127z=-1 128..#.... 129...#... 130#...... 131.....## 132.#...#. 133..#.#.. 134...#... 135 136z=0 137...#... 138....... 139#...... 140....... 141.....## 142.##.#.. 143...#... 144 145z=1 146..#.... 147...#... 148#...... 149.....## 150.#...#. 151..#.#.. 152...#... 153 154z=2 155....... 156....... 157..##... 158..###.. 159....... 160....... 161....... 162 163After the full six-cycle boot process completes, [1m[37m112[0m cubes are left in the 164[1m[37mactive[0m state. 165 166Starting with your given initial configuration, simulate six cycles. [1m[37mHow many cubes are 167left in the active state after the sixth cycle?[0m 168 169