A Rust implementation of a backtracking algorithm to solve Sudoku puzzles.
- Reads Sudoku puzzles from standard input
- Implements a backtracking algorithm with random number ordering for each cell
- Visual progress bar showing solving progress
- Colorful terminal output of the Sudoku board
- Comprehensive test suite for validation logic
Provide the Sudoku puzzle as a single line of 81 characters via standard input
- Use digits 1-9 for known cells
- Use any other character (e.g., '.', or space) for empty cells
Example:
echo "5.1..4..26.95.738...7...4....63.2.1.21......67..9..8243..6.12.896.7..1.5..52..67." | cargo run- The solver uses a backtracking approach with randomized digit ordering for each empty cell
- Board validation checks rows, columns, and 3x3 subgrids
- Progress is displayed using
indicatifprogress bar - Board is printed with colored borders for better visibility
colored- For colored terminal outputindicatif- For progress bar displayrand- For random number generationtap- For convenient collection manipulation
Run tests with:
cargo testThe solver uses an optimized backtracking approach:
- Processes empty cells in a specific order
- Maintains state for efficient backtracking
- Tracks maximum recursion depth reached
The program will display:
- The initial board
- A progress bar showing solving progress
- The solved board (if found)
- Statistics including iteration count
For unsolvable puzzles, it will report "No solution" with iteration statistics.