def set_d_edges(self, idx):
        slice_edge = [Ed.DR, Ed.DF, Ed.DL, Ed.DB]
        other_edge = [Ed.FR, Ed.FL, Ed.BL, Ed.BR, Ed.UR, Ed.UF, Ed.UL, Ed.UB]
        b = idx % 24  # Permutation
        a = idx // 24  # Location
        for e in Ed:
            self.ep[e] = -1  # Invalidate all edge positions

        j = 1  # generate permutation from index b
        while j < 4:
            k = b % (j + 1)
            b //= j + 1
            while k > 0:
                rotate_right(slice_edge, 0, j)
                k -= 1
            j += 1

        x = 4  # set slice edges
        for j in Ed:
            if a - c_nk(11 - j, x) >= 0:
                self.ep[j] = slice_edge[4 - x]
                a -= c_nk(11 - j, x)
                x -= 1

        x = 0  # set the remaining edges UR..DB
        for j in Ed:
            if self.ep[j] == -1:
                self.ep[j] = other_edge[x]
                x += 1
        for j in range(4):
            rotate_left(self.ep, 0, 11)
Example #2
0
 def get_slice(self):
     """Location of the UD-slice edges FR,FL,BL and BR ignoring their permutation."""
     a = x = 0
     # Compute the index a < (12 choose 4)
     for j in range(Ed.BR, Ed.UR - 1, -1):
         if Ed.FR <= self.ep[j] <= Ed.BR:
             a += c_nk(11 - j, x + 1)
             x += 1
     return a
    def set_slice(self, idx):
        slice_edge = list(range(Ed.FR, Ed.BR + 1))
        other_edge = [Ed.UR, Ed.UF, Ed.UL, Ed.UB, Ed.DR, Ed.DF, Ed.DL, Ed.DB]
        a = idx  # Location
        for e in Ed:
            self.ep[e] = -1  # Invalidate all edge positions

        x = 4  # set slice edges
        for j in Ed:
            if a - c_nk(11 - j, x) >= 0:
                self.ep[j] = slice_edge[4 - x]
                a -= c_nk(11 - j, x)
                x -= 1

        x = 0  # set the remaining edges UR..DB
        for j in Ed:
            if self.ep[j] == -1:
                self.ep[j] = other_edge[x]
                x += 1
 def get_slice_sorted(self):
     """Get the permutation and location of the UD-slice edges FR,FL,BL and BR.
         0 <= slice_sorted < 11880 in phase 1, 0 <= slice_sorted < 24 in phase 2, slice_sorted = 0 for solved cube."""
     a = x = 0
     edge4 = [0] * 4
     # First compute the index a < (12 choose 4) and the permutation array perm.
     for j in range(Ed.BR, Ed.UR - 1, -1):
         if Ed.FR <= self.ep[j] <= Ed.BR:
             a += c_nk(11 - j, x + 1)
             edge4[3 - x] = self.ep[j]
             x += 1
     # Then compute the index b < 4! for the permutation in edge4
     b = 0
     for j in range(3, 0, -1):
         k = 0
         while edge4[j] != j + 8:
             rotate_left(edge4, 0, j)
             k += 1
         b = (j + 1) * b + k
     return 24 * a + b
 def get_d_edges(self):
     """Get the permutation and location of the edges DR, DF, DL and DB.
         0 <= d_edges < 11880 in phase 1, 0 <= d_edges < 1680 in phase 2, d_edges = 0 for solved cube."""
     a = x = 0
     edge4 = [0] * 4
     ep_mod = self.ep[:]
     for j in range(4):
         rotate_right(ep_mod, 0, 11)
     # First compute the index a < (12 choose 4) and the permutation array perm.
     for j in range(Ed.BR, Ed.UR - 1, -1):
         if Ed.DR <= ep_mod[j] <= Ed.DB:
             a += c_nk(11 - j, x + 1)
             edge4[3 - x] = ep_mod[j]
             x += 1
     # Then compute the index b < 4! for the permutation in edge4
     b = 0
     for j in range(3, 0, -1):
         k = 0
         while edge4[j] != j + 4:
             rotate_left(edge4, 0, j)
             k += 1
         b = (j + 1) * b + k
     return 24 * a + b
Example #6
0
 def get_u_edges(self):
     """Permutation and location of edges UR, UF, UL and UB.
        u_edges  < 11880 in phase 1, u_edges  < 1656 + 24 in phase 2, u_edges = 1656 for solved cube."""
     a = x = 0
     edge4 = [0] * 4
     ep_mod = self.ep[:]
     for j in range(4):
         rotate_right(ep_mod, 0, 11)
     # First compute the index a < (12 choose 4) and the permutation array perm.
     for j in range(Ed.BR, Ed.UR - 1, -1):
         if Ed.UR <= ep_mod[j] <= Ed.UB:
             a += c_nk(11 - j, x + 1)
             edge4[3 - x] = ep_mod[j]
             x += 1
     # Then compute the index b < 4! for the permutation in edge4
     b = 0
     for j in range(3, 0, -1):
         k = 0
         while edge4[j] != j:
             rotate_left(edge4, 0, j)
             k += 1
         b = (j + 1) * b + k
     return 24 * a + b