Setting up the square…
Cube GraphSolving a Rubik's Cube with graph theory.
Scramble
·Solved.Every face one colour.
Follow on X
STICKER GRAPH · BIDIRECTIONAL BFS ON THE STATE GRAPH

Two graphs inside one cube.

The sticker graph. A cube has 54 stickers and 9 slices. Each slice carries a ring of 12 stickers round its edge, so make every sticker a vertex and join neighbours on a ring: 9 loops, 108 edges, and every sticker sits where exactly two loops cross, so every vertex has degree 4. Drawn with the loops as circles, three per axis and concentric, the six faces fall into six clusters of nine: three on the corners of a triangle and three on its sides. A quarter turn slides one loop three places; an outer turn also spins its face's eight stickers inside their cluster. The same graph is inlaid in the square below the cube, and it moves with it.

The state graph. Every arrangement of the cube is a vertex, 43,252,003,274,489,856,000 of them, and each of the 18 face turns (a quarter either way or a half, on six faces) is an edge. Solving is finding a path to the solved vertex. Solve runs a breadth-first search from the scramble and from the solved cube at once, always growing the smaller frontier, until the two meet; the path through the meeting point is a shortest one. Scrambles are 8 turns, so each side only has to look four turns deep: under a hundred thousand states in all. God's number says no position is more than 20 turns from solved.

Keys: U D L R F B and the middle slices M E S turn the cube (with Shift the other way) · N scramble · Enter solve · Space pause · A auto on or off · T tilt-shift · / hide the interface · ' (Ctrl ') playback controls · drag to orbit, scroll to zoom.

After The Math Flow's animation “Solving a Rubik's Cube with graph theory”.