← Mike Cogliandro

Cube Solver

Mix it up any way you like. The computer solves it by looking at it.

Everything runs in your browser.

Drag to look around
Solved Keyboard: U D L R F B · add Shift for the reverse turn
!
The computer is not remembering how you mixed it.

This page never keeps a list of your turns, only a count. When you press Solve, the solver is handed six photos of the cube and nothing else. OpenCV reads the 54 sticker colors from the pixels, and a solving algorithm plans the moves from what OpenCV saw.

What the computer saw

The photos below are everything the solver received. Each is taken with a slight tilt, uneven light and a little camera noise, so the vision steps have real work to do. The dots show the color OpenCV read for each sticker.

Laid out as if the cube were unfolded. Click any photo to see inside it below.

  1. 1
    Move history: none kept

    The solver never sees how the cube was mixed.

  2. 2
    Six photos taken

    One of each face, the only input the solver gets.

  3. 3
    OpenCV reads 54 stickers

    Finds the stickers, flattens each face and measures every color.

  4. 4
    Check that it’s a real cube

    Every corner and edge must match a real piece.

  5. 5
    Plan the moves

    Search for a short solution.

  6. 6
    Solve it

    Play the plan on the cube above.

Inside one photo

How OpenCV turns one photo into nine colors. Pick a face to follow it through every step.

Press Solve and this fills in with the computer’s own working.

How it works

Part 1

Seeing

A computer doesn’t see stickers, it sees a grid of numbers. OpenCV finds the bright, colorful patches, works out the outline of the face, and flattens it so the nine stickers land in predictable spots.

Colors are judged relative to each other, not against a fixed list. The center sticker of each face never moves, so the computer uses the six centers as its color reference, which keeps the reading steady in uneven light.

Part 2

Checking

One misread sticker makes a cube that can’t exist, and no algorithm can solve it. So before planning, the computer checks that there are nine of each color and that every corner and edge matches a real piece.

It also checks the hidden rules a real cube obeys. For example, you can never have a single corner twisted in place; corner twists always add up across the cube.

Part 3

Planning

The plan comes from Herbert Kociemba’s two-phase algorithm. Phase one gets the cube into a special family of positions that can be finished using only a few kinds of turns. Phase two finishes it using only those turns.

Splitting the problem makes an enormous search manageable, so it finds a solution of around 20 moves in well under a second.

43,252,003,274,489,856,000

Possible arrangements of a standard cube. Trying them one by one is out of the question; the computer has to reason its way there.

20 moves

Known as “God’s number.” In 2010, researchers proved every arrangement can be solved in 20 face turns or fewer.

0 moves remembered

The solver works only from what it sees, the same way it will work with a real cube held up to a webcam.