public void Part2() { const int TargetCycles = 6; const int Growth = 2 * (TargetCycles + 1); string[] input = File.ReadAllLines("Inputs/Day17.txt"); IntVec2 inputBounds = (input[0].Length, input.Length); IntVec4 bounds = ( inputBounds.X + Growth, inputBounds.Y + Growth, 1 + Growth, 1 + Growth); (IntVec4 low, IntVec4 high)bounding = ( (TargetCycles, TargetCycles, TargetCycles, TargetCycles), (inputBounds.X + TargetCycles + 2, inputBounds.Y + TargetCycles + 2, TargetCycles + 2, TargetCycles + 2)); bool[,,,] current = new bool[ bounds.X + 1, bounds.Y + 1, bounds.Z + 1, bounds.W + 1]; bool[,,,] next = (bool[, , , ])current.Clone(); for (int j = 0; j < input.Length; j++) { for (int i = 0; i < input[j].Length; i++) { current[i + TargetCycles + 1, j + TargetCycles + 1, TargetCycles + 1, TargetCycles + 1] = input[j][i] == '#'; } } IntVec4[] dirs = IntVec4.Zero.Surrounding().ToArray(); for (int cycles = 0; cycles < TargetCycles; cycles++) { for (int i = bounding.low.X; i <= bounding.high.X; i++) { for (int j = bounding.low.Y; j <= bounding.high.Y; j++) { for (int k = bounding.low.Z; k <= bounding.high.Z; k++) { for (int l = bounding.low.W; l <= bounding.high.W; l++) { bool active = current[i, j, k, l]; int adjActive = dirs.Count(adj => current[i + adj.X, j + adj.Y, k + adj.Z, l + adj.W]); next[i, j, k, l] = active ? adjActive is 2 or 3 : adjActive is 3; } } } } (current, next) = (next, current); bounding = (bounding.low - 1, bounding.high + 1); } int answer = 0; for (int i = 1; i < bounds.X; i++) { for (int j = 1; j < bounds.Y; j++) { for (int k = 1; k < bounds.Z; k++) { for (int l = 1; l < bounds.W; l++) { if (current[i, j, k, l]) { ++answer; } } } } } Assert.Equal(2012, answer); }
public PositionColorKey(Vector3 p, Color c) { position = new IntVec3(p); color = new IntVec4(c); }