Interface to several Rubik’s cube solvers.#

The first is by Michael Reid, and tries to find an optimal solution given the cube’s state, and may take a long time. See http://www.math.ucf.edu/~reid/Rubik/optimal_solver.html

The second is by Eric Dietz, and uses a standard (?) algorithm to solve the cube one level at a time. It is extremely fast, but often returns a far from optimal solution. See https://web.archive.org/web/20121212175710/http://www.wrongway.org/?rubiksource

The third is by Dik Winter and implements Kociemba’s algorithm which finds reasonable solutions relatively quickly, and if it is kept running will eventually find the optimal solution.

AUTHOR:

– Optimal was written by Michael Reid <reid@math.ucf.edu> (2004) – Cubex was written by Eric Dietz <root@wrongway.org> (2003) – Kociemba was written by Dik T. Winter <dik.winter@cwi.nl> (1993) – Initial interface by Robert Bradshaw (2007-08)

class sage.interfaces.rubik.CubexSolver#

Bases: object

format_cube(facets)#
solve(facets)#

EXAMPLES:

sage: from sage.interfaces.rubik import *      # optional - rubiks
sage: C = RubiksCube("R U")                    # optional - rubiks
sage: CubexSolver().solve(C.facets())          # optional - rubiks
'R U'
sage: C = RubiksCube("R U F L B D")            # optional - rubiks
sage: sol = CubexSolver().solve(C.facets()); sol  # optional - rubiks
"U' L' L' U L U' L U D L L D' L' D L' D' L D L' U' L D' L' U L' B' U' L' U B L D L D' U' L' U L B L B' L' U L U' L' F' L' F L' F L F' L' D' L' D D L D' B L B' L B' L B F' L F F B' L F' B D' D' L D B' B' L' D' B U' U' L' B' D' F' F' L D F'"
sage: RubiksCube(sol) == C                     # optional - rubiks
True
sage: C = RubiksCube("R2 F'")                  # optional - rubiks
sage: CubexSolver().solve(C.facets())          # optional - rubiks
"R' R' F'"
sage: C = RubiksCube().scramble()              # optional - rubiks
sage: sol = CubexSolver().solve(C.facets())    # optional - rubiks
sage: C == RubiksCube(sol)                     # optional - rubiks
True
class sage.interfaces.rubik.DikSolver#

Bases: object

facet_map = [1, 2, 3, 4, 0, 5, 6, 7, 8, 9, 10, 11, 17, 18, 19, 25, 26, 27, 33, 34, 35, 12, 0, 13, 20, 0, 21, 28, 0, 29, 36, 0, 37, 14, 15, 16, 22, 23, 24, 30, 31, 32, 38, 39, 40, 41, 42, 43, 44, 0, 45, 46, 47, 48]#
format_cube(facets)#
rot_map = {'B': 'U', 'D': 'B', 'F': 'D', 'L': 'L', 'R': 'R', 'U': 'F'}#
solve(facets, timeout=10, extra_time=2)#

EXAMPLES:

sage: from sage.interfaces.rubik import *   # optional - rubiks
sage: C = RubiksCube().move("R U")          # optional - rubiks
sage: DikSolver().solve(C.facets())         # optional - rubiks
'R U'
sage: C = RubiksCube().move("R U F L B D")  # optional - rubiks
sage: DikSolver().solve(C.facets())         # optional - rubiks
'R U F L B D'
sage: C = RubiksCube().move("R2 F'")        # optional - rubiks
sage: DikSolver().solve(C.facets())         # optional - rubiks
"R2 F'"
class sage.interfaces.rubik.OptimalSolver(verbose=False, wait=True)#

Bases: object

Interface to Michael Reid’s optimal Rubik’s Cube solver.

format_cube(facets)#
ready()#
solve(facets)#

The initial startup and precomputation are substantial…

Todo

Let it keep searching once it found a solution?

EXAMPLES:

sage: from sage.interfaces.rubik import *    # optional - rubiks
sage: solver = DikSolver()                   # optional - rubiks
sage: solver = OptimalSolver()  # optional - rubiks # long time (28s on sage.math, 2012)
Initializing tables...
Done.
sage: C = RubiksCube("R U")                  # optional - rubiks
sage: solver.solve(C.facets())               # optional - rubiks
'R  U'
sage: C = RubiksCube("R U F L B D")          # optional - rubiks
sage: solver.solve(C.facets())               # optional - rubiks
'R  U  F  L  B  D'
sage: C = RubiksCube("R2 D2")                # optional - rubiks
sage: solver.solve(C.facets())               # optional - rubiks
'R2 D2'
start()#
stop()#
class sage.interfaces.rubik.SingNot(s)#

Bases: object

This class is to resolve difference between various Singmaster notation.

Case is ignored, and the second and third letters may be swapped.

EXAMPLES:

sage: from sage.interfaces.rubik import SingNot
sage: SingNot("acb") == SingNot("ACB")
True
sage: SingNot("acb") == SingNot("bca")
False