Rubik's Cube: a real solving algorithm in PHP

The server scrambles a Rubik's Cube in PHP (or takes your own cube) and solves it with two methods. You can replay the solution step by step on the 3D cube: you see which face turns which way, and which stage of the method is running.

PHP is solving the cube…
Drag to freely rotate the view: this doesn't change the cube's state, only where you're looking from.

PHP is solving the cube…

Pace
Keys: ← → step, space play and pause, Home/End start and end.

How to read the moves

The cube is always held the same way: white center on top, green center facing you. The letter names the face that turns.

R
a quarter turn of that face, clockwise as you look straight at it
R'
the same, counterclockwise (the apostrophe means the opposite direction)
R2
a half turn (two quarters, direction does not matter)
Hover (or move keyboard focus to) a face letter or a move: the face lights up on the cube, and an arrow shows the turning direction.

Layer by layer vs. Kociemba: how does a computer solve the cube?

The layer-by-layer (beginner) method follows human logic: it solves the bottom layer first (cross, then corners), then the middle-layer edges, and finally the top layer in four steps. Here that is typically 120-150 moves, because every stage repeats short algorithms that keep the finished parts intact, but a person can learn the very same routine.

The Kociemba algorithm treats the cube as a mathematical structure and searches in two phases: first it reaches an intermediate state from which a restricted move set is enough, then it finishes with that. Precomputed tables tell the search how many moves are at least still needed, so it typically finds a 20-22 move solution in a few tenths of a second.

In 2010, a computer-assisted proof established that every possible cube state can be solved in at most 20 moves: this is God's Number, and the Kociemba algorithm gets close to this theoretical optimum.

The cube has about 43 quintillion (4.3x10^19) possible states: that is why brute-force guessing cannot solve it, and you need either a human strategy or a clever, group-theory-based search.