part2 (4451B)
1--- Part Two --- 2 3After careful analysis, one thing is certain: [1m[97myou have no idea where all these bugs are coming 4from[0m. 5 6Then, you remember: Eris is an old Plutonian settlement! Clearly, the bugs are coming from 7recursively-folded space. 8 9This 5x5 grid is [1m[97monly one[0m level in an [1m[97minfinite[0m number of recursion levels. The tile in the middle of 10the grid is actually another 5x5 grid, the grid in your scan is contained as the middle tile of a 11larger 5x5 grid, and so on. Two levels of grids look like this: 12 13 | | | | 14 | | | | 15 | | | | 16-----+-----+---------+-----+----- 17 | | | | 18 | | | | 19 | | | | 20-----+-----+---------+-----+----- 21 | | | | | | | | 22 | |-+-+-+-+-| | 23 | | | | | | | | 24 | |-+-+-+-+-| | 25 | | | |?| | | | 26 | |-+-+-+-+-| | 27 | | | | | | | | 28 | |-+-+-+-+-| | 29 | | | | | | | | 30-----+-----+---------+-----+----- 31 | | | | 32 | | | | 33 | | | | 34-----+-----+---------+-----+----- 35 | | | | 36 | | | | 37 | | | | 38 39(To save space, some of the tiles are not drawn to scale.) Remember, this is only a small part of 40the infinitely recursive grid; there is a 5x5 grid that contains this diagram, and a 5x5 grid that 41contains that one, and so on. Also, the ? in the diagram contains another 5x5 grid, which itself 42contains another 5x5 grid, and so on. 43 44The scan you took (your puzzle input) shows where the bugs are [1m[97mon a single level[0m of this structure. 45The middle tile of your scan is empty to accommodate the recursive grids within it. Initially, no 46other levels contain bugs. 47 48Tiles still count as [1m[97madjacent[0m if they are directly [1m[97mup, down, left, or right[0m of a given tile. Some 49tiles have adjacent tiles at a recursion level above or below its own level. For example: 50 51 | | | | 52 1 | 2 | 3 | 4 | 5 53 | | | | 54-----+-----+---------+-----+----- 55 | | | | 56 6 | 7 | 8 | 9 | 10 57 | | | | 58-----+-----+---------+-----+----- 59 | |A|B|C|D|E| | 60 | |-+-+-+-+-| | 61 | |F|G|H|I|J| | 62 | |-+-+-+-+-| | 63 11 | 12 |K|L|?|N|O| 14 | 15 64 | |-+-+-+-+-| | 65 | |P|Q|R|S|T| | 66 | |-+-+-+-+-| | 67 | |U|V|W|X|Y| | 68-----+-----+---------+-----+----- 69 | | | | 70 16 | 17 | 18 | 19 | 20 71 | | | | 72-----+-----+---------+-----+----- 73 | | | | 74 21 | 22 | 23 | 24 | 25 75 | | | | 76 77 78 - Tile 19 has four adjacent tiles: 14, 18, 20, and 24. 79 80 - Tile G has four adjacent tiles: B, F, H, and L. 81 82 - Tile D has four adjacent tiles: 8, C, E, and I. 83 84 - Tile E has four adjacent tiles: 8, D, 14, and J. 85 86 - Tile 14 has [1m[97meight[0m adjacent tiles: 9, E, J, O, T, Y, 15, and 19. 87 88 - Tile N has [1m[97meight[0m adjacent tiles: I, O, S, and five tiles within the sub-grid marked ?. 89 90 91The rules about bugs living and dying are the same as before. 92 93For example, consider the same initial state as above: 94 95....# 96#..#. 97#.?## 98..#.. 99#.... 100 101The center tile is drawn as ? to indicate the next recursive grid. Call this level 0; the grid 102within this one is level 1, and the grid that contains this one is level -1. Then, after 103[1m[97mten[0m minutes, the grid at each level would look like this: 104 105Depth -5: 106..#.. 107.#.#. 108..?.# 109.#.#. 110..#.. 111 112Depth -4: 113...#. 114...## 115..?.. 116...## 117...#. 118 119Depth -3: 120#.#.. 121.#... 122..?.. 123.#... 124#.#.. 125 126Depth -2: 127.#.## 128....# 129..?.# 130...## 131.###. 132 133Depth -1: 134#..## 135...## 136..?.. 137...#. 138.#### 139 140Depth 0: 141.#... 142.#.## 143.#?.. 144..... 145..... 146 147Depth 1: 148.##.. 149#..## 150..?.# 151##.## 152##### 153 154Depth 2: 155###.. 156##.#. 157#.?.. 158.#.## 159#.#.. 160 161Depth 3: 162..### 163..... 164#.?.. 165#.... 166#...# 167 168Depth 4: 169.###. 170#..#. 171#.?.. 172##.#. 173..... 174 175Depth 5: 176####. 177#..#. 178#.?#. 179####. 180..... 181 182In this example, after 10 minutes, a total of [1m[97m99[0m bugs are present. 183 184Starting with your scan, [1m[97mhow many bugs are present after 200 minutes?[0m 185 186