This project is an independent solver for the puzzle game Str8ts, developed purely for educational and recreational purposes. Str8ts is a registered trademark of Syndicated Puzzles Inc. All rights to the name, branding, and associated intellectual property belong to them. The author of this project is not affiliated, associated, authorized, endorsed by, or in any way officially connected with Syndicated Puzzles Inc., or any of its subsidiaries or affiliates.
The only Str8ts puzzle included in this repository is ''Str8ts9x9 Very Hard PUZ.png'' by AndrewCStuart from the German Wikipedia page, and is licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported License (CC BY-SA 3.0). This puzzle is used solely as an example to demonstrate the solver algorithm and is not licensed under the MIT License like the rest of the code in this repository. For full licensing details, refer to the LICENSE
file.
A Str8ts puzzle consists of a 9x9 board that must be filled according to the following rules:
- Each white cell must be filled with a number between 1 and 9, so that each number appears at most once in each row and column.
- Each compartment (a connected vertical or horizontal group of white cells) must contain a consecutive sequence of numbers in any order. For example,
$4,2,5,3$ would be a valid solution for a compartment with four cells, while$4,2,5,1$ would not be. - Black cells do not have to be filled with a number. If a black cell contains a number at the beginning, this number cannot appear in a white cell in the row or column.
To summarize, Str8ts is a Sudoku modification where some cells are black and do not need to be filled and the block constraints are replaced by compartment constraints. The German Wikipedia page gives two example puzzles and their solution, which can illustrate the initially somewhat confusing rules of Str8ts.
Str8ts generalized on an
In the standard encoding of a Sudoku puzzle into SAT we have variables
(A) Each white cell has at least one number, an empty black cell does not have a number
(B) Each number appears at most once per column/row
The big challenge is the encoding of rule 2, as the requirement for consecutive numbers in arbitrary order is very hard to translate into pure boolean logic. We will side-step this problem by introducing the alternative rule 2', proving the equivalence to rule 2 and then encode the former into SAT.
2'. If a compartment of length
Proof that rule 2 implies 2': If a compartment contains
Proof that rule 2' implies 2: We choose
Now we encode rule 2':
(C) Compartment constraints are satisfied
For all compartments
Then finally we ensure that the already placed numbers are accepted:
(D) Respect hints
Str8ts puzzles are inputed as a 81 character string, mapping the 81 cells starting from the top left corner to the bottom right corner. A white cell with number main.jl
we give the string representation for a diabolic Str8ts puzzle as an example.
The user can use solveSAT!(s::Str8ts)
, to encode the given Str8ts puzzle into pure SAT like described in the previous section and solve it with the PicoSAT SAT solver. Alternatively we provide solveSimple!(s::Str8ts)
, which is a 70 line backtracking solver again using rule 2'. While in general the more complicated SAT approach is far faster, both algorithms solve even diabolic Str8ts in a few millseconds as demonstrated in main.jl
.
(c) Mia Müßig