Skip to content

omidekz/soduko-solver

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 

Repository files navigation

python Sudoku Solver

you can use this class to solve an n*n sudoku by CSP solution

it's very simple to use for example i have an 3*3 sudoku:

from solver import Solver
table = [
    [0, 1, 0],
    [1, 0, 0],
    [0, 0, 0]
]
solver_object = Solver(table)
# solve method return an stack that contains the answer
# each level of answer pushed to this stack
stack_answer = solver_object.solve()
# if sudoku is unsolvable, the stack is empty
for level in stack_answer:
    for line_of_level_list in level:
        print(line_of_level_list)
    print()
    print()

"""
output:
[2, 1, 0]
[1, 0, 0]
[0, 0, 0]


[2, 1, 3]
[1, 0, 0]
[0, 0, 0]


[2, 1, 3]
[1, 0, 2]
[0, 0, 0]


[2, 1, 3]
[1, 3, 2]
[0, 0, 0]


[2, 1, 3]
[1, 3, 2]
[3, 0, 0]


[2, 1, 3]
[1, 3, 2]
[3, 2, 0]


[2, 1, 3]
[1, 3, 2]
[3, 2, 1]
"""

in addition

for 9*9 sudokus, we considered the sections

About

a python class that solve n*n sudoku

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages