AI solved the 3 × 3 × 3 puzzle
AI · Computer Vision · 3D Solver

Cube 3×3×3

6 unique pieces · 27 voxels · 1 solution

A classic 3×3×3 cube built from six interlocking polycube pieces. The AI reconstructs a digital twin of every piece from three photos, then a bitmask backtracking solver finds the unique assembly in milliseconds.

0.003 s AI solve time
14 941 Backtrack steps
8.3 h Time for a human

How AI finds the solution

1. Camera → 3D model

Three orthogonal photos of every piece are turned into a digital 3D model using Analysis-by-Synthesis — every mathematically possible polycube is rotated and projected back into theoretical silhouettes, and the one with the highest Jaccard IoU against the photo masks wins.

Piece 1 — front view Piece 1 — side view Piece 1 — top view
Three orthogonal photos · input for CV
CV-detected pieces
CV-detected 3D pieces

2. Backtracking solver

A bitmask DFS solver fills the cuboid voxel-by-voxel using the First-Empty-Cell heuristic and symmetry-breaking for duplicate pieces. Each placement is a single CPU bitwise-AND collision check.

Placing the first piece
Halfway through
Final piece slots in
Solver running

And the cube assembles itself

Drag to rotate · scroll to zoom — every colour is a different piece.
Target cuboid3 × 3 × 3
Unique piece types6
Total physical pieces6
Computer Vision phase9.36 s
Solver phase0.003 s
Backtrack iterations14 941
Solutions found1
Time for a human (8 h/day)1.0 days

Step-by-step guide

1

1. Photograph every piece

Take three orthogonal photos (front, side, top) of each unique piece on a contrasting background. Save them as 1a.jpg, 1b.jpg, 1c.jpg, 2a.jpg, …

2

2. Write config.yaml

Declare the cuboid size, the segment count of each unique piece, and how many physical copies of each you have. The optional thickness flag massively speeds up flat puzzles.

cuboid:
  x: 3
  y: 3
  z: 3

segments:
  "1": 5
  "2": 5
  "3": 2
  "4": 5
  "5": 5
  "6": 5
3

3. Computer Vision phase

cv_shape_matcher.py iterates over all polycubes matching the segment count, projects each rotation into three theoretical silhouettes, and picks the one with the highest IoU against the photo masks. The result is written to pieces.json.

4

4. Solver phase

solver.py compresses the build box into a single 27- or 64-bit integer. Each piece placement becomes a single bitwise AND collision check, so the inner loop runs at native CPU speed.

5

5. Run the pipeline

One command runs both phases and writes a 3D visualisation plus a statistics report into the output folder.

python main.py puzzle1

Why is AI so much faster?

Three optimisations carry the weight: bitmask collisions (a single CPU instruction instead of a loop), the First-Empty-Cell heuristic (cuts the branching factor by an order of magnitude), and grouping identical pieces (eliminates n! redundant permutations).

Try it yourself

All source code is MIT-licensed and freely available.