Skip to content

BruninLima/Project-Sudoku

Repository files navigation

Project-Sudoku

This repository now includes a Rust refactor focused on Sudoku solving and generation speed.

Rust Implementation

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_py module)
  • Criterion benchmarks for solver and generator performance
  • CLI commands for solving and generating puzzles

Usage

From the repo root:

cd rust-sudoku
cargo test

Solve a puzzle (0 or . for empty):

cargo run -- solve 800000000003600000070090200050007000000045700000100030001000068008500010090000400

Generate a puzzle:

cargo run -- generate 30 1234

Arguments:

  • generate [target_clues] [seed]
  • target_clues range: 17..=81
  • seed is optional and makes output deterministic

Python Bindings (PyO3)

Install tooling:

cd rust-sudoku
pip install maturin

Option A (inside an activated virtualenv):

maturin develop --release

Option B (no virtualenv required):

maturin build --release
python -m pip install --force-reinstall target/wheels/rust_sudoku_py-0.1.0-cp38-abi3-<platform>.whl

Python 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

Benchmarks

Run Criterion benchmarks:

cd rust-sudoku
cargo bench

Benchmark targets include:

  • solve_normal
  • solve_hard
  • generate_30_clues

Notes

The original Python prototype is still present under pydoku/.

About

Sudoku Solver and Generator with Python and Rust implementations.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors