A Python application that visually demonstrates and compares different algorithms for solving Sudoku puzzles.
This Sudoku Solver application visualizes how different algorithms approach and solve Sudoku puzzles. It generates a random puzzle and then solves it using four different algorithms, showing the step-by-step solution process and comparing their performance.
- Interactive visualization of Sudoku solving algorithms
- Real-time animation of solving process
- Performance comparison between different algorithms
- Color-coded visualization (fixed numbers, correct placements, backtracking)
- Summary view of performance metrics
-
Backtracking Algorithm: A depth-first search algorithm that explores possibilities until finding a solution, backtracking when necessary.
-
Divide and Conquer: An approach that focuses on solving 3×3 subgrids first, working through the puzzle section by section.
-
Greedy Algorithm: Uses heuristics to prioritize cells with the fewest possible valid numbers, making locally optimal choices at each step.
-
Recursive Algorithm: Similar to backtracking but with a different traversal pattern and number selection strategy.
- Python 3.6+
- Pygame 2.0.0+
- Clone this repository:
git clone https://github.com/kyazs/sudoku-solver.git
cd sudoku-solver
- Install the required packages:
pip install pygame
Run the program:
python sudoku.py
The application will:
- Generate a random Sudoku puzzle
- Solve it using each algorithm in sequence
- Display a performance comparison at the end
Press any key to exit after the comparison is shown.
- Puzzle Generation: Creates a fully solved Sudoku grid, then removes a percentage of numbers to create a puzzle
- Visualization:
- Gray cells: Fixed/initial numbers
- Green cells: Correctly placed numbers
- Red cells: Backtracked numbers (attempts that didn't work)
- Blue highlight: Currently processing cell
- Performance Measurement: Times each algorithm's solution process
Contributions are welcome! Feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.