https://github.com/shnarazk/sudoku_sat
Solving Sudoku variants with SAT solvers
https://github.com/shnarazk/sudoku_sat
rust sat-solver satisfiability sudoku
Last synced: about 1 month ago
JSON representation
Solving Sudoku variants with SAT solvers
- Host: GitHub
- URL: https://github.com/shnarazk/sudoku_sat
- Owner: shnarazk
- License: gpl-3.0
- Created: 2020-05-30T00:58:24.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-02-01T17:18:33.000Z (almost 2 years ago)
- Last Synced: 2024-05-22T22:33:35.161Z (over 1 year ago)
- Topics: rust, sat-solver, satisfiability, sudoku
- Language: Rust
- Homepage:
- Size: 211 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-rust-formalized-reasoning - sudoku_sat - solve Sudoku variants with SAT solvers. (Unclassified / Libraries)
README
# Solve Sudoku variants with SAT solvers
## Sudoku 400x400
under consruction
- https://github.com/hkociemba/sudokuNxM/tree/master/sudokus
- http://forum.enjoysudoku.com/giant-sudoku-s-16x16-25x25-36x36-100x100-t6578-150.html#p269691
## Sudoku 144x144
Solved.
```
git clone https://github.com/shnarazk/sudoku_sat.git
cd sudoku_sat
cargo run --bin sudoku144 --release < sudoku144.txt
```
- [Rust製のSATソルバーで144x144のSudokuを解こう(my blog entry in Japanese)](https://shnarazk.github.io/2021/2021-01-17-sudoku144/)
- https://github.com/shnarazk/sudoku_sat/discussions/4#discussioncomment-283483
## Sudoku 100x100
- https://github.com/shnarazk/sudoku_sat/discussions/4
- [Reducing the space](https://github.com/shnarazk/sudoku_sat/commit/361c4a9d44c9b413dd6f9a1a87a5cb8c3a929344)
## Sudoku 64
Solved.
```
git clone https://github.com/shnarazk/sudoku_sat.git
cd sudoku_sat
cargo run --bin sudoku64 --release
```
- [Rust製のSATソルバーで64x64のSudokuが解けるだろうか(my blog entry in Japanese)](https://shnarazk.github.io/2020/2020-12-18-sudoku64/)
## Sudoku 25
Solved.
- [Rust製の「SATソルバーで25x25のナンプレが解けるだろうか」(my blog entry in Japanese)](https://shnarazk.github.io/2020/2020-08-19-sudoku25/)
```
git clone https://github.com/shnarazk/sudoku_sat.git
cd sudoku_sat
cargo run --bin sudoku25 --release
```
## Miracle Sudoku
Solved.
- https://www.youtube.com/watch?v=cvEq_XkQg8U
### Approach
1. Preparation
```rust
struct Pos { i: isize, j: isize };
struct Cell { pos: Pos, digit: usize, on: bool };
```
2. Generate Sudoku rules and extra rules
```rust
for i in 1..=RANGE {
for j in 1..=RANGE {
let p = Pos::at(i, j);
for target_i in i..=RANGE {
for target_j in j..=RANGE {
let t = Pos::at(target_i, target_j);
for d in 1..=RANGE {
rules.push(p.state(d, true).requires(t.state(d, false));
}
}
}
}
}
```
3. Convert the rules to a CNF
4. Run SAT solver
### Result, the only one result
```plain
$ cargo run --release
Finished release [optimized] target(s) in 0.00s
Running `target/release/miracle_sudoku`
#rules: 22248
4 8 3 7 2 6 1 5 9
7 2 6 1 5 9 4 8 3
1 5 9 4 8 3 7 2 6
8 3 7 2 6 1 5 9 4
2 6 1 5 9 4 8 3 7
5 9 4 8 3 7 2 6 1
3 7 2 6 1 5 9 4 8
6 1 5 9 4 8 3 7 2
9 4 8 3 7 2 6 1 5
$
```

### Stats
```plain
$ tokei
-------------------------------------------------------------------------------
Language Files Lines Code Comments Blanks
-------------------------------------------------------------------------------
Markdown 1 56 56 0 0
Rust 5 281 239 30 12
TOML 1 11 7 1 3
-------------------------------------------------------------------------------
Total 7 348 302 31 15
-------------------------------------------------------------------------------
```