Welcome to the Sudoku Solver project! This is a Python implementation of a Sudoku puzzle solver using a backtracking algorithm. The solver can take a partially filled Sudoku grid and fill in the missing numbers to complete the puzzle.
🧮 Sudoku Board Representation: The Sudoku grid is represented as a 9x9 matrix where 0 represents an empty cell.
🚀 Backtracking Algorithm: Efficiently solves the Sudoku puzzle by trying all possible numbers in empty cells while ensuring the Sudoku rules are followed.
✔️ Validation: Checks the validity of the number placement according to Sudoku rules (row, column, and 3x3 sub-grid).
📋 Puzzle Display: Neatly prints the Sudoku grid before and after solving.
Below is an example of a Sudoku puzzle before and after being solved:
Puzzle before solving:
Puzzle after solving:
sudoku_solver.py: Contains the core logic for the Sudoku solver. The Game class is responsible for handling the grid, validating moves, and solving the puzzle using a backtracking approach.
printTable()
: Prints the Sudoku grid in a formatted manner.validNum(x, y, number)
: Checks if placing a number at a specific position is valid.solveProblem(x, y)
: Recursively solves the Sudoku puzzle.
🐍 Python 3.x installed on your system
- Clone the repository:
git clone https://github.com/yourusername/sudoku-solver.git
cd sudoku-solver
- Run the
sudoku_solver.py
file:
python sudoku_solver.py
The program will print the initial Sudoku grid, and then, if solvable, it will print the solved grid.
Contributions are welcome! If you'd like to improve this project, feel free to fork the repository and submit a pull request.
- Fork the repository.
- Create your feature branch:
git checkout -b feature/your-feature
- Commit your changes:
git commit -m 'Add some feature'
- Push to the branch:
git push origin feature/your-feature
- Open a pull request.