This repository now includes a Rust refactor focused on Sudoku solving and generation speed.
Path: rust-sudoku/
Implemented features:
- Fast Sudoku solver with backtracking + MRV (minimum remaining values) heuristic
- Solution counting with early cutoff (used for uniqueness checks)
- Sudoku puzzle generator from random full grids, removing clues while preserving uniqueness
- Python bindings via
pyo3(rust_sudoku_pymodule) - Criterion benchmarks for solver and generator performance
- CLI commands for solving and generating puzzles
From the repo root:
cd rust-sudoku
cargo testSolve a puzzle (0 or . for empty):
cargo run -- solve 800000000003600000070090200050007000000045700000100030001000068008500010090000400Generate a puzzle:
cargo run -- generate 30 1234Arguments:
generate [target_clues] [seed]target_cluesrange:17..=81seedis optional and makes output deterministic
Install tooling:
cd rust-sudoku
pip install maturinOption A (inside an activated virtualenv):
maturin develop --releaseOption B (no virtualenv required):
maturin build --release
python -m pip install --force-reinstall target/wheels/rust_sudoku_py-0.1.0-cp38-abi3-<platform>.whlPython usage:
import rust_sudoku_py
puzzle = "800000000003600000070090200050007000000045700000100030001000068008500010090000400"
solution = rust_sudoku_py.solve_puzzle(puzzle)
print(solution)
puzzle2, solution2 = rust_sudoku_py.generate_puzzle(30, 1234)
print(puzzle2)
print(rust_sudoku_py.count_puzzle_solutions(puzzle2, 2))Exported functions:
solve_puzzle(puzzle: str) -> Optional[str]generate_puzzle(target_clues: int = 30, seed: Optional[int] = None) -> tuple[str, str]count_puzzle_solutions(puzzle: str, limit: int) -> int
Run Criterion benchmarks:
cd rust-sudoku
cargo benchBenchmark targets include:
solve_normalsolve_hardgenerate_30_clues
The original Python prototype is still present under pydoku/.