https://github.com/robert27/sudokusolver
Simple Sudoko solver written in Python
https://github.com/robert27/sudokusolver
backtracking forward-checking python sudoku
Last synced: 3 months ago
JSON representation
Simple Sudoko solver written in Python
- Host: GitHub
- URL: https://github.com/robert27/sudokusolver
- Owner: Robert27
- License: mit
- Created: 2021-12-02T11:05:03.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2021-12-02T11:08:56.000Z (about 4 years ago)
- Last Synced: 2025-10-12T10:39:14.554Z (4 months ago)
- Topics: backtracking, forward-checking, python, sudoku
- Language: Python
- Homepage:
- Size: 3.91 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SudokuSolver
## Description
SudokuSolver is a simple Sudoku solver written in Python. The algorithm uses a recursive backtracking algorithm to solve
the puzzle.
### Input
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.
### Requirements
Minimum required Python version: 3.6
Incompatible version: 2
## Functions
### Function `test_solver`
> 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
## Classes
### Class `Sudoku`
> class Sudoku(
> path: str
> )
Sudoku Solver Class
Initializes the grid
:param path: Path to the grid file
### Static methods
##### `Method load_grid`
> 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
### Methods
##### Method `find_empty_cell`
> def find_empty_cell(
> self
> ) ‑> Optional[tuple]
Finds the first empty cell in the grid and returns its coordinates
:return: (row, column)
##### Method `print_grid`
> def print_grid(
> self
> ) ‑> None
Prints the grid to the console in a readable format
##### Method `recursive_solve`
> def recursive_solve(
> self
> ) ‑> bool
Recursive backtracking algorithm to solve the grid
:return: True if solved, False otherwise
##### Method `solve`
> def solve(
> self
> ) ‑> list
Solves the grid using the backtracking algorithm
:return: The solved grid
##### Method `time_taken`
> def time_taken(
> self
> ) ‑> float
Returns the time taken to solve the grid in milliseconds
:return: Time taken in milliseconds
##### Method `check`
> 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 ().