https://github.com/oniani/sat-sudoku
Implementation of the paper "Sudoku as a SAT Problem"
https://github.com/oniani/sat-sudoku
games np-hard python3 sat sudoku sudoku-solver
Last synced: about 2 months ago
JSON representation
Implementation of the paper "Sudoku as a SAT Problem"
- Host: GitHub
- URL: https://github.com/oniani/sat-sudoku
- Owner: oniani
- License: mit
- Created: 2018-12-05T17:29:35.000Z (over 7 years ago)
- Default Branch: main
- Last Pushed: 2021-11-15T14:23:45.000Z (over 4 years ago)
- Last Synced: 2025-10-30T03:09:05.443Z (9 months ago)
- Topics: games, np-hard, python3, sat, sudoku, sudoku-solver
- Language: Python
- Homepage:
- Size: 577 KB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SAT Sudoku Solver
This is the implementation of the SAT sudoku solver based on the paper by Inês Lynce and Jöel
Ouaknine titled _Sudoku as a SAT Problem_.
Sudoku is modeled as the SAT problem. The idea is to formulate a sudoku puzzle as a SAT formula if
the puzzle has a solution. Then we use the SAT program to find the solution.
SAT is a program that solves the satisfiability problem: given a formula, it either returns an
assignment that makes it true, or says that no such assignment exists. It uses a restricted form of
propositional formula called CNF (Conjunctive Normal Form). CNF consists of a set of clauses, each
of which is a set of literals. A literal is a variable or its negation. Each clause is interpreted
as the disjunction of its literals, and the formula as a whole is interpreted as the conjunction of
the clauses.
This project uses [MiniSat](http://minisat.se/)'s Rust reimplementation
[RatSat](https://github.com/qnighy/ratsat).
For the in-depth explanation of how the sudoku solver works, see the [paper](paper.pdf).
## API
```console
$ ./solve A_PATH_TO_THE_PUZZLE
```
## Examples
There are 9 sample sudoku puzzles available under directory named `puzzles`. To solve the first
puzzle, simply run `./solve puzzles/sudoku1.puzzle`.
## References
- [Inês Lynce and Jöel Ouaknine, Sudoku as a SAT Problem](paper.pdf)
- [RatSat](https://github.com/qnighy/ratsat)
- [MiniSat](http://minisat.se/)
- [Sudoku](https://en.wikipedia.org/wiki/Sudoku)
## License
[MIT License](LICENSE)