public IPocketDimension CalculateNextCycle() { var dimension = new PocketDimension4(SizeX + 2, SizeY + 2, SizeZ + 2, SizeW + 2); for (var w = 0; w < dimension.SizeW; w++) { for (var z = 0; z < dimension.SizeZ; z++) { for (var y = 0; y < dimension.SizeY; y++) { for (var x = 0; x < dimension.SizeX; x++) { var numActive = GetNumActiveNeightbours(x - 1, y - 1, z - 1, w - 1); var cube = GetSafeValue(x - 1, y - 1, z - 1, w - 1); if (cube == CubeType.Active) { cube = numActive == 2 || numActive == 3 ? CubeType.Active : CubeType.Inactive; } else { cube = numActive == 3 ? CubeType.Active : CubeType.Inactive; } dimension.Cubes[x, y, z, w] = cube; } } } } return(dimension); }
public static IPocketDimension FromLines(List <string> lines) { var dimension = new PocketDimension4(lines.First().Length, lines.Count, 1, 1); for (var y = 0; y < lines.Count; y++) { var line = lines[y]; for (var x = 0; x < line.Length; x++) { var cube = line[x] == '#' ? CubeType.Active : CubeType.Inactive; dimension.Cubes[x, y, 0, 0] = cube; } } return(dimension); }
static void Main() { var lines = File.ReadAllLines("input.txt").ToList(); var pockedDimension = PocketDimension3.FromLines(lines); for (var i = 0; i < 6; i++) { pockedDimension = pockedDimension.CalculateNextCycle(); } Console.WriteLine($"Part 1 - {pockedDimension.NumActive}"); pockedDimension = PocketDimension4.FromLines(lines); for (var i = 0; i < 6; i++) { pockedDimension = pockedDimension.CalculateNextCycle(); } Console.WriteLine($"Part 2 - {pockedDimension.NumActive}"); }