Sudoku solver with step-by-step guidance
Project description
Sudoku solver with step-by-step guidance
This lib is currently in pre-alpha phase, but already can solve some simple and medium level sudoku.
The following code displays all steps leading to solution:
from dokusan import entities, techniques
class Unsolvable(Exception):
pass
def list_steps(sudoku: entities.Sudoku):
all_techniques = (
techniques.PencilMarking,
techniques.LoneSingle,
techniques.HiddenSingle,
techniques.NakedPair,
techniques.NakedTriplet,
techniques.LockedCandidate,
techniques.XYWing,
techniques.UniqueRectangle,
)
while not sudoku.is_solved():
for technique in all_techniques:
try:
result = technique(sudoku).first()
except techniques.NotFound as exc:
continue
else:
sudoku.update(result.changes)
yield result
break
raise Unsolvable
_ = 0
sudoku = entities.Sudoku.from_list([
[_, _, _, _, 9, _, 1, _, _],
[_, _, _, _, _, 2, 3, _, _],
[_, _, 7, _, _, 1, 8, 2, 5],
[6, _, 4, _, 3, 8, 9, _, _],
[8, 1, _, _, _, _, _, _, _],
[_, _, 9, _, _, _, _, _, 8],
[1, 7, _, _, _, _, 6, _, _],
[9, _, _, _, 1, _, 7, 4, 3],
[4, _, 3, _, 6, _, _, _, 1],
])
for step in list_steps(sudoku):
print(step.combination)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
dokusan-0.1.0a1.tar.gz
(18.0 kB
view hashes)
Built Distribution
dokusan-0.1.0a1-py3-none-any.whl
(18.5 kB
view hashes)
Close
Hashes for dokusan-0.1.0a1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 575a03a843c98f9adf46c4daad2c03a04c55a7b0700bd1d217544aa727dd4a12 |
|
MD5 | 0b164e04055380eab5a554b698480f92 |
|
BLAKE2b-256 | 0573030e0745f6f5aed19fcc0385fa61ec7b3d65086ed8cc887114eb6a4e5170 |