docs(readme): add algorithm, input format, and example

This commit is contained in:
tiennm99 committed 2026-05-11 21:40:27 +07:00
1 parent a81ee8a1e1
commit c6ad7ad414
1 file changed
+32 -3
+32 -3
View File
@@ -1,6 +1,35 @@
# sudoku-solver
Sudoku solver written in PHP.
9×9 Sudoku solver in PHP using recursive backtracking — runs from the browser or CLI, prints solution to stdout.
## Algorithm
Recursive backtracking: iterates through empty cells, tries digits 1–9, and backtracks on constraint violations (row, column, and 3×3 box checks).
## Input format
Edit `sudoku.php` to define the puzzle as an 81-character string — digits 1–9 for known cells, `0` for empty cells:
```php
$puzzle = new SudokuSolver("530070000600195000098000060800060003400803001700020006060000280000419005000080079");
$puzzle->solve();
```
## Example
Input:
```
5 3 0 | 0 7 0 | 0 0 0
6 0 0 | 1 9 5 | 0 0 0
0 9 8 | 0 0 0 | 0 6 0
```
Output (stdout):
```
5 3 4 | 6 7 8 | 9 1 2
6 7 2 | 1 9 5 | 3 4 8
1 9 8 | 3 4 2 | 5 6 7
```
## Usage
@@ -8,8 +37,8 @@ Sudoku solver written in PHP.
php sudoku.php
```
Edit `sudoku.php` to define the puzzle (9×9 grid with `0` for empty cells).
Or open `sudoku.php` in a browser for the interactive grid UI.
## License
Apache-2.0
Apache-2.0 — see [LICENSE](LICENSE).