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