A solver for the 2x2 Rubik's Cube — also known as the Pocket Cube or Mini Cube — running entirely in the terminal with a colored ANSI rendering of the cube.
The solver combines a breadth-first search with a pre-calculation step:
- All 24 orientations of the solved cube are generated as target states.
- From those targets, every state reachable within
LEVEL_OF_PRECALCULATIONmoves (default:4) is enumerated and cached. - A BFS from the scrambled state runs until it meets the cached set.
Meeting in the middle roughly halves the effective search depth, which keeps the state space tractable without shipping a full pattern database.
- Python 3.9 or newer — no third-party dependencies
- A terminal with ANSI color support
git clone https://github.com/michaelkrisper/pyRubik2x2.git
cd pyRubik2x2Nothing to build or install.
python3 rubik.pyOpens a prompt where you can turn faces manually, randomize the cube, and ask for a solution.
python3 rubik.py <cube-state>Passes the cube state directly as an argument; the solver prints the move sequence that returns it to solved.
| File | Purpose |
|---|---|
rubik.py |
Entry point — interactive loop, pre-calculation, BFS solver |
cube.py |
RubikCube class — state representation, rotations, rendering |
run.bat |
Convenience launcher for Windows |
MIT — see LICENSE.
