|
Sudoku Showcase
|
Solves Sudoku puzzles using a combination of constraint propagation and recursive backtracking. More...
Public Member Functions | |
| def | __init__ (self, Puzzle puzzle) |
| set[tuple[int]] | solutions (self) |
| (property) The unique solutions found by the solver. More... | |
| None | mergeSolutions (cls, "Solver" this, "Solver" other) |
| (classmethod) Merge the solutions of the solver. More... | |
| None | printSolutions (self) |
| Function to print the found solution console. More... | |
| bool | solve (self) |
| Solve the puzzle. More... | |
Public Attributes | |
| puzzle | |
Solves Sudoku puzzles using a combination of constraint propagation and recursive backtracking.
The solving process follows two stages:
The constraint propagation step acts as an optimizer to reduce the search space efficiently, but does not guarantee completeness or uniqueness of the solution on its own.
The backtracking algorithm selects the field with the fewest remaining candidates, clones the current puzzle state, applies one candidate, and then continues solving recursively with a new Solver instance.
If multiple valid solutions are detected during recursion, the solving process aborts to preserve uniqueness checks.
The Solver is primarily used for generating and validating uniquely solvable puzzles. While the implementation focuses on readability and understandability rather than maximum optimization, it still performs efficiently even on sparse puzzles.
| def sudoku.solver.Solver.__init__ | ( | self, | |
| Puzzle | puzzle | ||
| ) |
| None sudoku.solver.Solver.mergeSolutions | ( | cls, | |
| "Solver" | this, | ||
| "Solver" | other | ||
| ) |
| None sudoku.solver.Solver.printSolutions | ( | self | ) |
Function to print the found solution console.
| set[tuple[int]] sudoku.solver.Solver.solutions | ( | self | ) |
(property) The unique solutions found by the solver.
A solution is a serialized puzzle with no empty fields. To add a solution
| bool sudoku.solver.Solver.solve | ( | self | ) |
Solve the puzzle.
Tries to solve the Puzzle using chain of constraints and if stuck, brute force
| sudoku.solver.Solver.puzzle |