| Crates.io | sudosolve |
| lib.rs | sudosolve |
| version | 0.1.1 |
| created_at | 2025-01-04 18:13:53.277458+00 |
| updated_at | 2025-01-04 18:36:57.537658+00 |
| description | A Rust crate for solving Sudoku puzzles. It takes a Sudoku puzzle input and provides the solved grid. |
| homepage | |
| repository | https://github.com/NithinKonda/sudoku-solver |
| max_upload_size | |
| id | 1504128 |
| size | 8,076 |
Sudosolve is a Rust crate for solving Sudoku puzzles. It takes a Sudoku puzzle as input in string format and provides the solved grid if a solution exists. The crate uses a backtracking algorithm to efficiently solve puzzles.
You can install sudosolve directly from crates.io using Cargo:
cargo install sudosolve
Usage
Example
Here's an example of how to use the crate:
use sudosolve::SudokuBoard;
fn main() {
let input = "53__7____6__195___98____6_8___6___34__8_3__17___2___6_6____28___419__5____8__79"; // Replace with your Sudoku string
let mut board = SudokuBoard::new(&input);
println!("Original Sudoku:");
board.print();
if board.solve() {
println!("\nSolved Sudoku:");
board.print();
} else {
println!("\nNo solution exists.");
}
}
The input string represents the Sudoku grid, where each row is concatenated into a single string. Use _ or 0 for empty cells.
Input Format
Provide the puzzle as an 81-character string, with digits (1 to 9) for filled cells and _ or 0 for empty cells.
Rows are concatenated from left to right, top to bottom.
Example Input
53__7____
6__195___
98____6__
8___6___3
4__8_3__1
7___2___6
_6____28_
___419__5
____8__79
Should be provided as:
53__7____6__195___98____6_8___6___34__8_3__17___2___6_6____28___419__5____8__79
Development and Testing
Clone the repository and build the crate locally:
git clone https://github.com/NithinKonda/sudoku-solver.git
-> cd sudosolve
-> cargo build
-> cargo test
This project is licensed under the MIT License.
Contributions are welcome! Feel free to open issues or submit pull requests on GitHub.
The solver uses a backtracking algorithm that:
Searches for the first empty cell.
Attempts to place each number (1-9) in the cell.
Checks the validity of the placement using Sudoku rules.
Recursively continues until the puzzle is solved or deemed unsolvable.
Happy solving with sudosolve!