SudokuSolver is a simple Sudoku solver written in Python. The algorithm uses a recursive backtracking algorithm to solve the puzzle.
Inputs are in the form of a txt file containing a 9x9 grid of numbers in the range 0-9.
- 0 represents an empty cell
- 1-9 represents a given number.
sudokus_test/ contains a collection of puzzles to test the solver.
Minimum required Python version: 3.6
Incompatible version: 2
def test_solver( path: str ) ‑> None
Tests the solver on all the grids in the given path
:param path: Path to the folder containing the grids
class Sudoku( path: str )
Sudoku Solver Class
Initializes the grid
:param path: Path to the grid file
def load_grid( path: str ) ‑> list
Loads the grid from a file and returns it as a list of lists
:param path: Path to the file
:return: List of lists
def find_empty_cell( self ) ‑> Optional[tuple]
Finds the first empty cell in the grid and returns its coordinates
:return: (row, column)
def print_grid( self ) ‑> None
Prints the grid to the console in a readable format
def recursive_solve( self ) ‑> bool
Recursive backtracking algorithm to solve the grid
:return: True if solved, False otherwise
def solve( self ) ‑> list
Solves the grid using the backtracking algorithm
:return: The solved grid
def time_taken( self ) ‑> float
Returns the time taken to solve the grid in milliseconds
:return: Time taken in milliseconds
def check( self, digit: int, position: tuple ) ‑> bool
Checks if the number is valid in the row, column and region
:param digit: Number to check
:param position: (row, column)
:return: True if valid, False otherwise
Generated by pdoc 0.10.0 (https://pdoc3.github.io).