static void Main(string[] args) { Cubes = new List <Cube>(); Cubes.Add(new Cube { Top = Color.Blue, Bottom = Color.White, Front = Color.Red, Left = Color.Green, Back = Color.White, Right = Color.Red }); Cubes.Add(new Cube { Top = Color.Green, Bottom = Color.White, Front = Color.Blue, Left = Color.Red, Back = Color.Red, Right = Color.Red }); Cubes.Add(new Cube() { Top = Color.Red, Bottom = Color.Green, Front = Color.Blue, Left = Color.Green, Back = Color.Blue, Right = Color.White }); Cubes.Add(new Cube() { Front = Color.White, Bottom = Color.White, Left = Color.Blue, Back = Color.Blue, Right = Color.Red }); int counter = 0; for (int i = 0; i < 4; i++) { Cubes[i].RotateLeft(); for (int j = 0; j < 4; j++) { Cubes[i].RotateDown(); for (int k = 0; k < 4; k++) { Cubes[k].RotateLeft(); for (int l = 0; l < 4; l++) { Cubes[k].RotateDown(); for (int m = 0; m < 4; m++) { Cubes[m].RotateLeft(); for (int n = 0; n < 4; n++) { Cubes[m].RotateDown(); for (int o = 0; o < 4; o++) { Cubes[o].RotateLeft(); for (int p = 0; p < 4; p++) { Cubes[o].RotateDown(); for (int q = 0; q < 4; q++) { for (int r = q; r < 4; r++) { Cube temp = Cubes[q]; Cubes[q] = Cubes[r]; Cubes[r] = temp; if (CheckCubes()) { Console.WriteLine("yasy"); goto yay; } counter++; } } } } } } } } } } yay: int nah = 1; foreach (var cube in Cubes) { Console.WriteLine(nah++ + "---------------------"); Console.WriteLine("Top: " + cube.Top.ToString()); Console.WriteLine("Bottom: " + cube.Bottom.ToString()); Console.WriteLine("Front: " + cube.Front.ToString()); Console.WriteLine("Left: " + cube.Left.ToString()); Console.WriteLine("Back: " + cube.Back.ToString()); Console.WriteLine("Right: " + cube.Right.ToString()); } Console.WriteLine(counter); Console.ReadKey(); ////break padlock //for (int i = 0; i < length; i++) //{ // for (int j = 0; j < length; j++) // { // for (int k = 0; k < length; k++) // { // for (int l = 0; l < length; l++) // { // i, j, k, l // } // } // } //} }
static void Puzzle(double equation) { int n = 32; Console.WriteLine($"#of cubes: {n}"); Cube[] cubes = new Cube[n]; for (int i = 0; i < cubes.Length; i++) { cubes[i] = new Cube(); } //Setup Puzzle int a, b, c; a = b = c = 0; for (int i = 1; i <= 192; i++) { cubes[a].opposites[b].colors[c] = 1 + (int)(i * equation) % 32; c++; if (c > 1) { c = 0; b++; if (b > 2) { b = 0; a++; } } } //print initial setup Console.WriteLine("#\tOpp1\tOpp2\tOpp3"); for (int i = 0; i < cubes.Length; i++) { Console.Write($"{i + 1}"); for (int j = 0; j < cubes[i].opposites.Length; j++) { Console.Write($"\t({cubes[i].opposites[j].colors[0]},{cubes[i].opposites[j].colors[1]})"); } Console.WriteLine(""); } //Check for obstacles //Check for mono cube & cube with adj with same color int mono = FindMono(cubes); if (mono != -1) { Console.WriteLine("Mono cube found at"); //Search for cube with an adjacent color int adj = FindAdj(cubes, cubes[mono].opposites[0].colors[0]); if (adj != -1) { Console.WriteLine($"Obstacle Found: Mono cube at {mono} with similar adjs colors at cube {adj}"); return; } } else { Console.WriteLine("No mono cubes found"); } //bubble sort by average color to increase search times Console.WriteLine("Sorting by average color..."); bool sorting = true; while (sorting) { sorting = false; for (int i = 0; i < cubes.Length - 1; i++) { if (ColorAverage(cubes[i]) > ColorAverage(cubes[i + 1])) { Cube temp = cubes[i + 1]; cubes[i + 1] = cubes[i]; cubes[i] = temp; sorting = true; } } } //Depth First Search for Solution Console.WriteLine("Searching for solution with compact Depth First Search..."); List <Pair> bankA = new List <Pair>(); bankA.Add(new Pair(0, 0)); bankA.Add(cubes[0].opposites[1]); Console.Write("Thread A: "); FindThread(bankA, cubes, n); //Print Solution foreach (Pair p in bankA) { Console.Write($"({p.colors[0]},{p.colors[1]}) "); } if (bankA.Count != 0) { List <Pair> bankB = new List <Pair>(); bankB.Add(new Pair(0, 0)); Console.Write("\nThread B: "); FindThread(bankB, cubes, n); foreach (Pair p in bankB) { Console.Write($"({p.colors[0]},{p.colors[1]}) "); } } Console.WriteLine("\n"); }