public void set_d_edges(int idx) { var b = idx % 24; var a = idx / 24; //Array.Fill(_edgePositions, -1); var sliceEdge = DSliceEdge.ToArray(); var j = 1; while (j < 4) { var k = b % (j + 1); b /= j + 1; while (k > 0) { sliceEdge.rotate_right(0, j); k -= 1; } j += 1; } var sliceX = 4; var otherX = 0; foreach (var j2 in Extensions.GetEnumValues <Edge>().Cast <int>()) { if (a - Miscellaneous.BinomialChoose(11 - j2, sliceX) >= 0) { _edgePositions[j2] = sliceEdge[4 - sliceX]; a -= Miscellaneous.BinomialChoose(11 - j2, sliceX); sliceX -= 1; } else { _edgePositions[j2] = DOtherEdge[otherX]; otherX += 1; } } for (var j4 = 0; j4 < 4; j4++) { _edgePositions.rotate_left(0, 11); } }
/// <summary> /// Get the location of the UD-slice edges FR,FL,BL and BR ignoring their permutation. /// Slice is between 0 and 494 inclusive in phase 1. /// Slice is zero in phase 2. /// </summary> public static ushort get_slice(this ICubieCube cubieCube) { var a = 0; var x = 0; // Compute the index a < (12 choose 4) for (var j = 11; j >= 0; j--) { if (Edge.Fr > cubieCube.EdgePositions[j] || cubieCube.EdgePositions[j] > Edge.Br) { continue; } a += Miscellaneous.BinomialChoose(11 - j, x + 1); x += 1; } Debug.Assert(a <= 495); return(Convert.ToUInt16(a)); }
private static ushort GetEdges(this ICubieCube cubieCube, int offset) { var a = 0; var x = 0; var edge4 = new int[4]; var epMod = cubieCube.EdgePositions.ToArray(); for (var k = 0; k < 4; k++) { epMod.rotate_right(0, 11); } // First compute the index a < (12 choose 4) and the permutation array perm. for (var j = 11; j >= 0; j--) { var epModJ = (int)epMod[j]; if (offset <= epModJ && epModJ <= 3 + offset) { a += Miscellaneous.BinomialChoose(11 - j, x + 1); edge4[3 - x] = epModJ; x += 1; } } // Then compute the index b < 4! for the permutation in edge4 var b = 0; for (var j = 3; j > 0; j--) { var k = 0; while (edge4[j] != j + offset) { edge4.rotate_left(0, j); k += 1; } b = (j + 1) * b + k; } return(Convert.ToUInt16(24 * a + b)); }
/// <summary> /// Get the permutation and location of the UD-slice edges FR,FL,BL and BR. /// Between 0 and 11879 inclusive in phase 1. /// Between 0 and 24 in phase 2. /// 0 for solved cube. /// </summary> /// <param name="cubieCube"></param> /// <returns></returns> public static ushort get_slice_sorted(this ICubieCube cubieCube) { var a = 0; var x = 0; var edge4 = new Edge[4]; // First compute the index a < (12 choose 4) and the permutation array perm. for (var j = 11; j >= 0; j--) { var edge = cubieCube.EdgePositions[j]; if (Edge.Fr <= edge && edge <= Edge.Br) { a += Miscellaneous.BinomialChoose(11 - j, x + 1); edge4[3 - x] = edge; x += 1; } } // Then compute the index b < 4! for the permutation in edge4 var b = 0; for (var j = 3; j > 0; j--) { var k = 0; while ((int)edge4[j] != j + 8) { edge4.rotate_left(0, j); k += 1; } b = (j + 1) * b + k; } var r = 24 * a + b; return(Convert.ToUInt16(r)); }
public void set_slice_sorted(int idx) { var b = idx % 24; var a = idx / 24; var mySliceEdge = SliceEdge.ToArray(); var j = 1; while (j < 4) { var k = b % (j + 1); b /= j + 1; while (k > 0) { mySliceEdge.rotate_right(0, j); k -= 1; } j += 1; } var sliceX = 4; var otherX = 0; foreach (var j2 in Extensions.GetEnumValues <Edge>().Cast <int>()) { if (a - Miscellaneous.BinomialChoose(11 - j2, sliceX) >= 0) { _edgePositions[j2] = mySliceEdge[4 - sliceX]; a -= Miscellaneous.BinomialChoose(11 - j2, sliceX); sliceX -= 1; } else { _edgePositions[j2] = OtherEdge[otherX]; otherX += 1; } } }
public void set_slice(ushort idx) { var a = Convert.ToInt32(idx); var sliceX = 4; //set slice edges var otherX = 0; foreach (var j in Extensions.GetEnumValues <Edge>().Cast <int>()) { var a1 = a - Miscellaneous.BinomialChoose(11 - j, sliceX); if (a1 >= 0) { _edgePositions[j] = SliceEdge[4 - sliceX]; sliceX -= 1; a = a1; } else { _edgePositions[j] = OtherEdge[otherX]; otherX += 1; } } }