public override object SolveOne() { var world = new World3D(); for (int x = 0; x < Rows.Count; x++) { for (int y = 0; y < Rows[x].Length; y++) { if (Rows[x][y] == '#') { world.SetValue(x, y, 0, true); } } } for (int i = 0; i < 6; i++) { world = world.Run(); } return(world.Sum(x => x.Value.Sum(y => y.Value.Count(z => z.Value)))); }
public World3D Run() { int loX = Keys.Min(); int hiX = Keys.Max(); int loY = Values.Min(x => x.Keys.Min()); int hiY = Values.Max(x => x.Keys.Max()); int loZ = Values.Min(x => x.Values.Min(y => y.Keys.Min())); int hiZ = Values.Max(x => x.Values.Max(y => y.Keys.Max())); var output = new World3D(); for (int x = loX - 1; x <= hiX + 1; x++) { for (int y = loY - 1; y <= hiY + 1; y++) { for (int z = loZ - 1; z <= hiZ + 1; z++) { int nCount = CountNeighbors(x, y, z); output.SetValue(x, y, z, nCount == 3 || (GetValue(x, y, z) && nCount == 2)); } } } return(output); }