This is the core module of a Sudoku solver project. It provides the logic for solving 9x9 Sudoku puzzles using an efficient backtracking algorithm. This module is designed to be part of a larger project that includes features like OCR and image processing for extracting Sudoku puzzles from images.
- Solve 9x9 Sudoku puzzles using a backtracking algorithm.
- Validate puzzle input for correctness and consistency.
- Display puzzles in a user-friendly format.
- Designed for integration with other modules (e.g., OCR, image processing).
- Timeout Functionality: Solve puzzles within a user-defined time limit.
- Interactive Mode: Accept puzzles via user input or use default puzzles.
- Python 3.10 or higher
- Virtual environment (recommended)
To use the Sudoku Solver Core package:
pip install git+https://github.com/yrangana/Sudoku-Solver-Core.git@main
To contribute or run tests, install with development dependencies:
pip install git+https://github.com/yrangana/Sudoku-Solver-Core.git@main[dev]
For local development, clone the repository and install it in editable mode:
git clone https://github.com/yrangana/Sudoku-Solver-Core.git
cd Sudoku-Solver-Core
pip install -e .[dev]
This project includes a Makefile
for common development tasks:
-
Install Dependencies: Install all required dependencies:
make install
-
Run Tests: Execute the test suite:
make test
-
Format Code: Format all Python files using
black
:make format
-
Lint Code: Lint all Python files using
pylint
:make lint
-
Clean Temporary Files: Clean up temporary files and cache:
make clean
-
Run Project: If applicable, run the project locally:
make run
-
Import and use the Sudoku Solver Core in your Python project:
from src.solver import solve_sudoku puzzle = [ [5, 3, 0, 0, 7, 0, 0, 0, 0], [6, 0, 0, 1, 9, 5, 0, 0, 0], ... ] if solve_sudoku(puzzle): print("Solved Puzzle:", puzzle) else: print("No solution exists.")
-
Interactive Mode: Run the
main.py
script to interact with the solver:python main.py
Features:
- Choose between a default puzzle or input your own.
- Set a timeout for solving the puzzle.
Example of input for custom puzzles:
Enter your Sudoku puzzle row by row, using 0 for empty cells. Row 1: 5 3 0 0 7 0 0 0 0 Row 2: 6 0 0 1 9 5 0 0 0 ... Row 9: 0 0 0 0 8 0 0 7 9
- None (currently no runtime dependencies)
black
: Code formattingclick
: CLI supportipython
: Interactive shellpylint
: Code lintingpytest
: Testing frameworksetuptools
: Packaging and build tool
- Clone the repository:
git clone https://github.com/yrangana/Sudoku-Solver-Core.git
- Install dependencies for development:
pip install -e .[dev]
- Run tests to verify:
pytest
- Install the package in other projects using:
pip install git+https://github.com/yrangana/Sudoku-Solver-Core.git@main
This project is licensed under the MIT License. See the LICENSE
file for details.
- Thanks to the open-source community for Python and Sudoku solving resources.