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.
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.
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.
And the cube assembles itself
| Target cuboid | 3 × 3 × 3 |
|---|---|
| Unique piece types | 6 |
| Total physical pieces | 6 |
| Computer Vision phase | 9.36 s |
| Solver phase | 0.003 s |
| Backtrack iterations | 14 941 |
| Solutions found | 1 |
| Time for a human (8 h/day) | 1.0 days |
Step-by-step guide
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. 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. 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. 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. 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.