Python Sudoku solver using backtracking algorithm and the great Pandas package.
Note: Green numbers in the screenshot above represent input values from the puzzle file.
- Windows OS (tested for Windows 10)
- Windows Terminal supporting ANSI Escape Sequences (for cursor positioning and colors)
- Python packages: pandas and csutils.cterm
The setup below assumes that Python 3, PIP and venv are already installed on your Linux or Windows WSL system.
git clone https://github.com/cwsoft/sudoku.git
cd ./sudoku
python3 -m venv .venv
source .venv/bin/activate
pip install -r ./requirements.txt
clear
Prepare a textfile with a Sudoku puzzle you can´t solve or you are too lazy to do manually. A Sudoko puzzle file consists of numbers [0-9] placed in a 9x9 grid, where the number 0 indicates a free slot. The column numbers in each row needs to be separated with a single space. Use # at the beginning of a line for adding comments to the puzzle file.
Hint: Invoke the script with --interactive to see the backtracking algorithm in action.
usage: sudoku.py [-h] [--space SPACE] [--interactive] sudokufile
positional arguments:
sudokufile Input file with Sudoku puzzle to solve.
optional arguments:
-h, --help show this help message and exit
--space SPACE Char used for free puzzle slots [Default: '.'].
--interactive Outputs each single step (may slowdown hard problems).
The Python Sudoku solver is published under MIT License.
Have fun cwsoft