Egor Urvanov

AI Rubik's Cube solver beats 1,000+ teams on 4×4×4 and 5×5×5How the neural network works

How the CayleyPy neural network solves a Rubik's Cube in the fewest moves: how many combinations a cube has, why brute force is impossible, how a compass learns from random scrambles, and why a wide search front and a squad of networks matter. Results on 3×3×3, 4×4×4 and 5×5×5, a diagram walkthrough of arXiv 2502.13266.

· 15 min · · Research

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.

1 move19 moresolvedthe goal of any solvetop face ↻ by ¼move = turning one facescrambledposition = how faces are colored

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.

×8 corners3 colors each8! places × 3⁷ twists≈ 88 million12 edges2 colors each12! places × 2¹¹ flips≈ 981 billion88 M × 981 B ÷ 2 = 43,252,003,274,489,856,000÷ 2: half the colorings can’t occur on a real cube · face centers never move

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.

2025250030003395start · 1 billion positions per second≈ 1,370 years for one 3×3×3 cube

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.

3×3×34.3·10¹⁹4×4×47.4·10⁴⁵5×5×52.8·10⁷⁴atoms on Earth ≈ 10⁵⁰bar length = number of digits

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.

CubePositionsWhat is known about shortest paths
3×3×34.3·10¹⁹God's number: 20 moves (half turn = 1 move), 26 moves (quarter turns only)
4×4×47.4·10⁴⁵a conjecture of 48 moves, not proven
5×5×52.8·10⁷⁴unknown
Takeaway
In this exampleFor 4×4×4 and 5×5×5 cubes a full search is impossible, and shortest paths are unknown.
In generalWhen the state space is huge, shortest paths are searched without enumeration: with a distance estimate and a smart search. Quality is checked on tasks with a known or best-known answer.
Next stepBefore judging that “AI solved the problem”, find out what it is compared with: a proven optimum or the best known solution.

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.

AlexanderChervovKirillKhoruzhiiNikitaBukhalJalalNaghiyevVladislavZamkovoyIvanKoltsovLyudmilaCheldievaArseniiSychevArseniiLeninMarkObozovEgorUrvanovauthor of this blogAlexeyRomanov12 authors · CayleyPy · Moscow, Paris, Munich · arXiv, 18 February 2025

Authors in the paper's order. The author of this blog is one of the co-authors.

Kaggle Santa 20231,000+ teams1 dot ≈ 10 teamsscore = total movesaverage solution length, moves4×4×4best teams · 53.5CayleyPy · 46.5−7.05×5×5best teams · 96.6CayleyPy · 92.2−4.4shorter is better · 4×4×4: 43 tasks, 5×5×5: 19

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.

doorright face ↻room = one coloringneighboring roomdiffers by the right face

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.

now12 doors →top↻top↺bottom↻bottom↺front↻front↺back↻back↺right↻right↺left↻left↺↻ clockwise · ↺ counterclockwise — looking straight at that face

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.

exitsolvedcubestartyourcube87654321shortest path — 9 moves · number = moves leftthick line = wall · a cube room has 12 doors, the sketch has up to 4

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.

9876543210exit · 0the solved cubestart · 9your cubeheight = moves to the exit · blue steps = the shortest way down

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.

1234567walk from the exit · number = move counttraining records→1 move→2 moves→3 moves→7 movesbillions of such pairs

Left: a walk through the maze; right: the records the network learns from. ▶ 2:44

Walkrandom moves from the solved cube, never stepping straight back
Lengthup to 26 moves for 3×3×3, 45 for 4×4×4, 65 for 5×5×5
Recordposition → moves made so far
Volume8 billion positions; 1 million fresh ones before each training round

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.

inputcoloring · 54 stickersneural network10 layers · 4 M parameters≈ 17outputmoves to solve

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.

dashed = walk · blue = real paththe walk recorded8 movesactually2 movesthe compass overestimates,but farther from the exitstill means a bigger number

Why the compass overestimates. ▶ 3:06

Input
The cube position: a list of numbers saying where each of the 54 stickers is now
Network
10 layers, 4 million parameters; trained on 8 billion positions from walks
Output
An estimate of how many moves remain to the solved cube

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.

1364667101454571011013869434661111107654610912exitsolvedcubestartyourcubedead endnumber = moves to the exit according to the compass (off by −1…+2)a single path trusts the compass and can’t turn back

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.

876543543218763218542176exitsolvedcubestartyourcubeblue rooms = front · number = step · path — 9 moveseach step keeps the 3 most promising rooms

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.

compass 113 movescompass 211 movescompass 39 moves● exit · ○ start · each compass learned from its own walks · the answer is the shortest

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.

solver · 46.5
+7 for the best teams

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 of 19 tasks · 92.2 moves vs 96.6 on average

19 out of 19. ▶ 5:02

CubeTask setBest before the paperCayleyPy
3×3×31,000 positions from the DeepCubeA work60.3% and 69.6% shortest paths (DeepCubeA, EfficientCube)98.4%, 26 compasses
4×4×443 positions, Kaggle Santa 202353.49 moves on average46.51 moves, 29 compasses
5×5×519 positions, Kaggle Santa 202396.58 moves92.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.

width 1dead endrooms checked: 9width 211 movesrooms checked: 29width 39 movesrooms checked: 33blue rooms = visited by the front · wider front = more compass errors forgiven

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.

65 K60.2
262 K56.7
1 M55.3
4 M52.8
16 M50.6

Front width and average path on the 4×4×4 cube, moves. Table III of the paper.

Takeaway
In this exampleEach doubling of the width cuts roughly the same number of moves from the path.
In generalOf all settings, the front width affects the result the most — more than network size or the amount of data.
Next stepWhen the distance estimate is imprecise, invest in search width rather than in a perfect estimate.

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

Takeaway
In this exampleAn ensemble of 10 different compasses is up to 8 moves shorter than the best of them.
In generalWhen an answer is easy to check, several independently trained models with best-answer selection give more than polishing one model.
Next stepIf checking an answer is cheap, run several different models and take the best result.

Surprises

Three observations the authors call unexpected.

more data is not betteravg 4×4×4 path · billion positions55.4455.1855.816a small network is betterparameters, millions14.7previous4compassfastertraining, hours86.4previous4.7compassblue = CayleyPy; solving on the same machine is 26× faster: 10.9 s vs 287.8 s

Data, network size, time. ▶ 6:37

  1. 1
    More data is not better
    Beyond 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
  2. 2
    A small compass is more accurate
    4 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
  3. 3
    Faster
    Training 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.

Walkscheap data, no map
Compassmoves-to-exit estimate
Frontforgives compass errors
Squadshortest of the answers

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 videoIn the paperHow it works
mazeCayley (Schreier) graph of the cube groupvertices are positions, edges are moves
positionpermutation(p(0), …, p(53)): where each of the 54 stickers went; a move shifts 20 stickers
walkpairs (position, k)the average k is the diffusion distance; it exceeds the shortest one
compassResMLP neural network10 layers, 4 M parameters, minimizes (estimate − k)²; 1 M fresh positions before each training round
frontbeam searchneighbors → dedupe → estimate → W best; W up to 2²⁴, at most 200 steps
squadagentsanswer length = min(L₁, …, L_A) over agents
001122334455667788… 53… 53beforeafterposition = (p(0), …, p(53)) · a move shifts 20 stickers

A position is a permutation: like a shuffled deck — same cards, different order. 9 of the 54 stickers shown. ▶ 8:15

frontWneighborsW × 12no repeatscompass scoreW bestWrepeat until the solved cube is in the front

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 False

Where 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.

LinkWhere
directpuzzles: cubes of any size, the Kaggle Santa competition
directshortest paths in huge permutation graphs where enumeration is impossible
authors' plansproblems from biology and programming
analogyplanning: 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

  1. 1
    1974
    Ernő Rubik invents the cube
  2. 2
    2010
    Proven: any 3×3×3 position can be solved in 20 moves when a half turn counts as one move
  3. 3
    2014
    Proven: in 26 moves when only quarter turns are counted
  4. 4
    2019
    The DeepCubeA network from the University of California, Irvine solves the regular cube without human hints for the first time
  5. 5
    2023
    Kaggle Santa competition: 1,000+ teams solve big cubes
  6. 6
    2025
    The 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

Can a neural network solve a Rubik's Cube?
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.
How many combinations does a 3×3×3 Rubik's Cube have?
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⁷⁴.
What is the fewest number of moves to solve any Rubik's Cube?
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.
How is CayleyPy different from DeepCubeA?
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%.
Can I try it myself?
Yes: the authors' code is open, the CayleyPy library is on GitHub (link below).
Numbers are from the paper by A. Chervov, K. Khoruzhii, …, E. Urvanov, A. Romanov, arXiv 2502.13266 (tables I–III, figures 2–3). The drawn maze and its numbers are a sketch; its paths are computed by beam search. The author of this blog is one of the paper's co-authors.
  • AI agent
  • research
  • neural networks
  • Rubik's Cube
  • Rubik's Cube solver
  • pathfinding
© 2026 Egor Urvanov