public void ReturnFalse_WhenCubesAreNotEqual(string otherCubeCoordenates) { var otherCube = new Cube4D(otherCubeCoordenates, true); var sut = new Cube4D("x=2,y=2,z=2", true); Assert.False(sut.Equals(otherCube)); }
public static void Task2() { Console.WriteLine("AOC2020_Day17_2"); var cube = new Cube4D(); cube.Load(6); for (int i = 0; i < 6; i++) { cube.Step(); } Console.WriteLine("Sum : {0}", cube.GetActiveSum()); }
public override int ActiveNeighbors(Cube cube, bool addIfMissing = true) { var neighbours = 0; int xIndex = cube.x; int yIndex = cube.y; int zIndex = cube.z; int wIndex = (cube as Cube4D).w; // -1, 0, 1 List <int> xs = Enumerable.Range(-1, 3).Select(nr => nr + xIndex).ToList(); List <int> ys = Enumerable.Range(-1, 3).Select(nr => nr + yIndex).ToList(); List <int> zs = Enumerable.Range(-1, 3).Select(nr => nr + zIndex).ToList(); List <int> ws = Enumerable.Range(-1, 3).Select(nr => nr + wIndex).ToList(); foreach (var x in xs) { foreach (var y in ys) { foreach (var z in zs) { foreach (var w in ws) { if (x == xIndex && y == yIndex && z == zIndex && w == wIndex) { // this is the cube we have continue; } var index = $"{x},{y},{z},{w}"; if (Cubes.ContainsKey(index)) { var neighbour = Cubes[index]; if (neighbour.IsActive) { neighbours++; } } else if (!NewCubes.ContainsKey(index) && addIfMissing) { var newCube = new Cube4D(x, y, z, w); newCube.IsActive = false; NewCubes.Add(newCube.Index, newCube); } } } } } return(neighbours); }
public CubeSpace4D(int xSize, int ySize, int zSize, int wSize) { _cubes = new Cube4D[xSize, ySize, zSize, wSize]; for (int x = 0; x < xSize; x++) { for (int y = 0; y < ySize; y++) { for (int z = 0; z < zSize; z++) { for (int w = 0; w < wSize; w++) { _cubes[x, y, z, w] = new Cube4D(this, x, y, z, w); } } } } }
public ConwayCubes4D(List <string> input) : base() { Cubes = new Dictionary <string, Cube>(); NewCubes = new Dictionary <string, Cube>(); int z = 0; int w = 0; for (int x = 0; x < input.Count(); x++) { var row = input[x]; for (int y = 0; y < row.Count(); y++) { var value = row[y]; bool isActive = value == '#'; // . == false if (isActive) { var cube = new Cube4D(x, y, z, w); cube.IsActive = isActive; Cubes.Add(cube.Index, cube); } } } }