Sudoku Solver - Modular Rust Workspace
A comprehensive, modular Rust library and application suite for solving advanced Sudoku puzzles of various sizes (3x3, 4x4, 5x5, and more) using multiple solving strategies, with WebAssembly (WASM) and terminal UI support.
Installation
Add the core library to your Rust project:
[]
= "0.3"
# For WebAssembly support
= { = "0.3", = ["wasm"] }
Install the terminal UI application:
For WebAssembly projects, use the core library with WASM features enabled.
Features
- Multiple Grid Sizes: 4x4 (2x2), 9x9 (3x3), 16x16 (4x4), 25x25 (5x5), and more
- Advanced Solving Strategies: Naked/Hidden Singles, Pairs, X-Wing, Swordfish, and more
- Backtracking Algorithm: For hard puzzles
- WebAssembly Support: Use the library in web browsers
- Puzzle Generation: Create new puzzles with difficulty levels
- Validation & Hints: Check solutions and get next-move suggestions
- Statistics: Track solving performance and strategy usage
- Simple Text UIs: Both TUI and WASM use lightweight text rendering
Project Structure
This workspace consists of two main crates:
📚 sudoko - Core Library with WASM Support
- Located in
sudoko/ - Provides all puzzle logic, solving, generation, validation, and CLI
- Includes WebAssembly support when built with
--features wasm - Public API:
Sudoku,SudokuSolver,Cell,Difficulty, and utilitiesWasmSudokuand WASM utilities (whenwasmfeature is enabled)
🖥️ sudoko-tui - Terminal User Interface
- Located in
sudoko-tui/ - Simple interactive terminal UI (WASD navigation, number input, solve, etc.)
- Uses only the public API from the core library
- No external UI dependencies
Building and Running
Prerequisites
- Rust 1.70+ with Cargo
Build All Crates
Build Individual Crates
# Core library
# Core library with WASM support
# Terminal UI
Running Applications
CLI Interface
# Solve a puzzle
# Generate a puzzle
# Get help
Terminal UI
WebAssembly (WASM)
Use the provided build-wasm.sh script to build for web, node, and bundler targets:
See web-example/ for a browser demo.
Usage Examples
Core Library (Rust)
use ;
// Create a new puzzle
let mut puzzle = new;
// Load from string
let puzzle = from_string?;
// Solve the puzzle
let mut solver = new;
let solution = solver.solve?;
// Generate a new puzzle
let puzzle = solver.generate_puzzle?;
WASM (JavaScript)
import from './pkg/sudoko.js';
// Create a new puzzle
const sudoku = ;
// Load an example puzzle
const example = ;
// Solve it
example.;
// Render as text
console.log;
Architecture Benefits
- Unified Codebase: Core logic and WASM interface are in one crate, reducing duplication
- Optional Features: WASM support is feature-gated, keeping the core library lightweight
- Reusability: The core library can be used in any Rust project with or without WASM
- Simple UIs: TUI uses simple text rendering with no heavy dependencies
- Clean API: Well-defined public interfaces for all functionality
Development Notes
- All crates use only the public API from the core library, ensuring clean boundaries and maintainable code.
- The core library uses feature flags to keep WASM dependencies optional.
- The implementations avoid heavy dependencies, making them lightweight and easy to integrate into different environments.
License
MIT