The AI Rubik's Cube solver works in three steps: a neural network learns from random scrambles how many moves are left, a beam search follows its estimate through millions of positions at once, and several independent networks run in parallel, keeping the shortest solution. This beat the best of 1,000+ teams on 4×4×4 and 5×5×5 cubes.
Video: the same story in 12 minutes
This post follows the video scene by scene and goes into more detail. Under the diagrams is a link to that moment of the video, which is narrated in Russian.
Paper: A Machine Learning Approach That Beats Large Rubik's Cubes, arXiv 2502.13266, 18 February 2025. Maze, compass, front and squad are images for explaining; in the paper they are the Cayley graph, the neural network, beam search and the ensemble.
The question: solving a cube is easy, solving it in the fewest moves is hard
Anyone can learn to solve a Rubik's Cube in an evening from a guide. A guide gives a long solution, usually 50–100 moves or more. The shortest solution is a different problem, and for big cubes nobody knows how to find it yet.
Two words we will need. A move is a quarter turn of one face. A position is how the faces are colored right now. A face turn takes the cube from one position to another. The paper's question: how to get from a given position to the solved one in the fewest moves.
Left: solved; middle: after one move; right: after 20 random moves. ▶ 0:12
Why not follow a guide and cut the extra moves? A guide solves the cube layer by layer, and each step temporarily breaks and repairs what is already done. That takes several times more moves than the minimum. To find the minimum you would have to compare every possible path, and there are far too many.
How many combinations does a Rubik's Cube have
A regular 3×3×3 Rubik's Cube has 43,252,003,274,489,856,000 combinations — about 43 quintillion, too many to check one by one. That is why solving it in the fewest moves is hard.
The number comes from the pieces. A cube has 8 corners (3 colors each) and 12 edges (2 colors each); face centers never move. Corners can be placed in 8! ways and twisted in 3⁷ ways — the last corner's twist is fixed by the others. Edges can be placed in 12! ways and flipped in 2¹¹ ways. Half of the combinations can't occur on a real cube (you can't swap exactly two pieces without taking it apart), so the product is divided by two.
Left: only corners are bright; right: only edges. ▶ 0:34
Checking a billion positions per second, a full search of a regular cube would take about 1,370 years: start in 2025, finish in 3395.
Full search at a billion positions per second. ▶ 0:41
Bigger cubes have more pieces, and the number grows even faster. A 5×5×5 cube has more positions than there are atoms on Earth.
Bar length is the number of digits in the position count. ▶ 0:51
For the regular cube the minimum is known. God's number is the largest number of moves the shortest solution of any position can need. It was found by computer search with symmetry shortcuts: 20 moves when a half turn counts as one move (2010), and 26 moves when only quarter turns are counted (2014). For 4×4×4 and 5×5×5 there is no such answer.
| Cube | Positions | What is known about shortest paths |
|---|---|---|
| 3×3×3 | 4.3·10¹⁹ | God's number: 20 moves (half turn = 1 move), 26 moves (quarter turns only) |
| 4×4×4 | 7.4·10⁴⁵ | a conjecture of 48 moves, not proven |
| 5×5×5 | 2.8·10⁷⁴ | unknown |
The paper, the authors and the competition
In 2023, more than a thousand teams of programmers competed on Kaggle in Santa 2023: who could solve puzzles, big cubes included, in the fewest total moves.
Kaggle is a platform where companies and researchers post problems and teams from around the world compete on solutions. Santa 2023 had a simple score: the total number of moves across all puzzles, lower is better. The competition's best answers became the bar for big cubes.
On 18 February 2025, twelve authors of the CayleyPy project posted the paper “A Machine Learning Approach That Beats Large Rubik's Cubes”. Their program beat the competition's best answers on 4×4×4 and 5×5×5 cubes and became the first neural network to solve cubes bigger than the regular one.
Authors in the paper's order. The author of this blog is one of the co-authors.
The competition and the result: average solution length, moves. ▶ 1:17
The cube as a maze of positions
The central picture: each position is a room, each move is a door to a neighboring room, the solved cube is the exit.
A room is one coloring of the cube. Turn a face and you are in the neighboring room. It is a neighbor because the coloring differs by one turn.
On the right is the same coloring with the right face turned. ▶ 1:35
Every room of a regular cube has 12 doors: the cube has 6 faces, each can be turned clockwise or counterclockwise.
All 12 neighboring rooms: behind every door is a different coloring. ▶ 1:45
All rooms together form the maze — in mathematics, the Cayley graph of the cube group. There is always one exit: the solved cube. The start is your scrambled cube, the position you need to solve. Solving the cube in the fewest moves means getting from the start to the exit through the fewest doors.
Below is a toy maze of 40 rooms. The real one has 4.3·10¹⁹ rooms with 12 doors each, so it can't be drawn; the small one shows how each part of the program works.
Exit on the left, start on the right, thick lines are walls. ▶ 2:12
Now raise every room to a height equal to its number of moves to the exit. You get a relief: the exit is the lowest point, and the shortest path from any room is a walk down a staircase, each step one lower. If every room's height were known, solving would be easy: always step down. Nobody knows the heights — that is what the neural network will guess.
The relief of the same maze. ▶ 1:59
A walk from the exit
Nobody has a map of the maze: there are too many rooms. So the authors work backwards.
They stand at the exit and make random moves — a walk, which is just scrambling the solved cube. After each move they record the coloring and how many moves have been made. The computer generates such “position → number of moves” pairs by the billion right during training: a walk costs almost nothing and needs no map.
Left: a walk through the maze; right: the records the network learns from. ▶ 2:44
The compass: a network that guesses the distance to the exit
The compass learns from the walks: it looks at a coloring and guesses how many moves are left to the exit — the room's height on the relief.
The compass is an ordinary neural network: a coloring in, a number out.
The compass is wrong, and wrong on the high side: a walk loops around, so it takes more moves than the shortest path. On the sketch a walk reaches a room in 8 moves while the room is really 2 moves away. But the farther a walk went, the farther the room is from the exit on average, so the compass points the right way: a smaller number means closer to the exit. The authors call the average number of walk moves to a position the diffusion distance.
Why the compass overestimates. ▶ 3:06
The compass is the first part of the authors' program. Below we call the whole program the solver: compass, front and squad.
The front: why one path is not enough
Walking a single path wherever the compass points, one compass mistake leads into a dead end.
The simple way to follow a compass: from the current room step into the neighbor with the smaller number. On the sketch the numbers in rooms are the estimates of a compass that is off by one or two moves. The single path takes three steps, enters a room where the compass was wrong, and hits a wall.
A single path following the compass. ▶ 3:37
So the solver moves as a front — beam search in the paper. A front is several rooms at once. At every step the solver opens all doors from all rooms of the front, the compass rates the new neighbors, and only the most promising go on. How many rooms to keep is the width of the front; the authors go up to 2²⁴ ≈ 16 million. If the compass is wrong about one room, other rooms of the front are still there and the path doesn't break.
The same compass, a front of width 3. ▶ 4:09
The squad: several compasses and the shortest answer
Each compass learns from its own random walks, so two compasses are wrong about different rooms.
The authors assemble a squad: several independently trained networks, each with its own front. Each searches on its own, and the shortest path found becomes the answer. Checking an answer is cheap — just count the moves — so extra networks never hurt; they only add chances of a shorter path.
Three compasses with different errors on the same maze. ▶ 4:36
Results
Three cubes, three stories.
Regular 3×3×3 cube. The solver finds the shortest possible path in 98 cases out of 100. The previous best networks — DeepCubeA (2019) and EfficientCube (2023) — managed 60 and 70.
98 of 100 tasks — shortest path (precisely, 98.4% on 1,000 positions from the DeepCubeA work). ▶ 4:43
4×4×4 cube. The solver's path is on average 7 moves shorter than the best competition teams: 46.5 versus 53.5. That is below the conjectured limit of 48 moves.
5×5×5 cube. The solver is shorter than the best teams on every one of the 19 competition tasks: 92.2 moves versus 96.6 on average.
19 out of 19. ▶ 5:02
| Cube | Task set | Best before the paper | CayleyPy |
|---|---|---|---|
| 3×3×3 | 1,000 positions from the DeepCubeA work | 60.3% and 69.6% shortest paths (DeepCubeA, EfficientCube) | 98.4%, 26 compasses |
| 4×4×4 | 43 positions, Kaggle Santa 2023 | 53.49 moves on average | 46.51 moves, 29 compasses |
| 5×5×5 | 19 positions, Kaggle Santa 2023 | 96.58 moves | 92.16 moves, 69 compasses |
Table I of the paper.
Why: the width of the front
A compass mistake in one room is corrected by the other rooms of the front, so the wider the front, the shorter the path found.
On the sketch, the same compass hits a dead end at width 1, finds an 11-move path at width 2 and the shortest, 9 moves, at width 3. The paths are computed by a real beam search. The price of width is time: a wider front checks more rooms.
Same compass, different front width. ▶ 5:31
In the paper, on the 4×4×4 cube, a front 256 times wider cut the path from 60 moves to 50, and each doubling of width cut roughly the same number of moves.
Front width and average path on the 4×4×4 cube, moves. Table III of the paper.
Why: the squad
For the 5×5×5 cube the authors trained 69 compasses. On each task the one with the shorter path wins, and the paths of 10 of them made it into the final answers.
Even weak compasses turned out useful: each won one or two hard tasks. Together the squad finds paths up to 8 moves shorter than the best compass alone. And the very first 4×4×4 compass beat all the best competition answers by itself — and still didn't make the final set: the others together were shorter.
69 compasses for 5×5×5; the 10 whose paths made the answer are highlighted. Which ones exactly is a sketch; in the paper this is figure 3. ▶ 6:02
Surprises
Three observations the authors call unexpected.
Data, network size, time. ▶ 6:37
- 1More data is not betterBeyond 8 billion positions the compass barely improves: 4, 8 and 16 billion give an average path of 55.4, 55.1 and 55.8 moves on the 4×4×4 cube
- 2A small compass is more accurate4 million parameters versus 14.7 million in previous networks — almost four times smaller and still more accurate; even a single-layer network reaches 90.4% shortest paths
- 3FasterTraining takes 4 h 40 min instead of 86 h 25 min; solving a cube on the same machine with the same front width takes 10.9 s versus 287.8 s, about 26 times faster
The takeaway
The question was: can you find a short solution for a huge cube without checking every position? You can.
Three parts are enough: a compass learns from random walks away from the exit, a wide front forgives its mistakes, and a squad of different compasses picks the shortest path. The solver knows nothing about the cube itself — only rooms and doors — so it fits other mazes too.
Caveat. Shortest paths for big cubes are unknown, so the solver is compared with the best known solutions, not with the optimum.
Formally: the same path in the paper's language
The second part of the video: the same steps as formulas.
| In the video | In the paper | How it works |
|---|---|---|
| maze | Cayley (Schreier) graph of the cube group | vertices are positions, edges are moves |
| position | permutation | (p(0), …, p(53)): where each of the 54 stickers went; a move shifts 20 stickers |
| walk | pairs (position, k) | the average k is the diffusion distance; it exceeds the shortest one |
| compass | ResMLP neural network | 10 layers, 4 M parameters, minimizes (estimate − k)²; 1 M fresh positions before each training round |
| front | beam search | neighbors → dedupe → estimate → W best; W up to 2²⁴, at most 200 steps |
| squad | agents | answer length = min(L₁, …, L_A) over agents |
A position is a permutation: like a shuffled deck — same cards, different order. 9 of the 54 stickers shown. ▶ 8:15
One beam search step: like a tournament round, the best go through. ▶ 9:39
Beam search in a few lines; the authors published full PyTorch code with the paper.
def beam_search(start, model, W, steps=200):
front = [start]
for _ in range(steps):
nbrs = unique(move(v) for v in front for move in MOVES)
if SOLVED in nbrs: return True
front = sorted(nbrs, key=model)[:W] # W best by the compass
return FalseWhere it helps
The solver doesn't know it is looking at a cube: it only needs positions, moves and a goal. So the same approach fits any problem of getting from one state to another along the shortest path.
| Link | Where |
|---|---|
| direct | puzzles: cubes of any size, the Kaggle Santa competition |
| direct | shortest paths in huge permutation graphs where enumeration is impossible |
| authors' plans | problems from biology and programming |
| analogy | planning: a robot or a game that must get from one state to another |
Lesson. With no map, train a compass on random walks and move as a wide front.
Who and when, what is proven
- 11974Ernő Rubik invents the cube
- 22010Proven: any 3×3×3 position can be solved in 20 moves when a half turn counts as one move
- 32014Proven: in 26 moves when only quarter turns are counted
- 42019The DeepCubeA network from the University of California, Irvine solves the regular cube without human hints for the first time
- 52023Kaggle Santa competition: 1,000+ teams solve big cubes
- 62025The CayleyPy paper: the first neural network to beat everyone on 4×4×4 and 5×5×5
This is an experiment, not a proof: the numbers are measured on task sets from earlier work and from the competition, and shortest paths for big cubes are unknown. The average path of 46.5 moves on the 4×4×4 cube is below the conjectured limit of 48 moves, but the conjecture itself is not proven. Several numbers in the paper disagree: the share of shortest paths on a regular cube is given as both 98.4% and 97.6%, and the number of networks in the 4×4×4 squad below 48 moves as both 29 and 6.
FAQ
Yes. Neural networks have solved the regular cube since 2019 (DeepCubeA), and in 2025 CayleyPy became the first neural network to solve 4×4×4 and 5×5×5 cubes, in fewer moves than the best competition teams.
43,252,003,274,489,856,000 — about 4.3·10¹⁹. A 4×4×4 has about 7.4·10⁴⁵, a 5×5×5 about 2.8·10⁷⁴.
The regular 3×3×3 cube needs at most 20 moves when a half turn counts as one move, and 26 when only quarter turns are counted. For bigger cubes the exact answer is unknown.
Its network is almost four times smaller and trains about 18 times faster, and the search runs as a wide front with a squad of networks. On the regular cube that gives 98% shortest paths versus 60%.
Yes: the authors' code is open, the CayleyPy library is on GitHub (link below).