A full-featured Sudoku solver with both web interface and command-line interface. This application allows you to input Sudoku puzzles, solve them automatically, and interact with the board through an intuitive web UI or terminal interface.
- Web Interface: Modern, responsive web UI with interactive Sudoku board
- Command-Line Interface: Terminal-based interaction for puzzle solving
- Multiple Input Methods:
- Build entire boards from text input
- Insert/delete individual digits
- Click-to-select cells in web interface
- Intelligent Solver:
- Detects unique solutions
- Identifies when no solution exists
- Warns when multiple solutions are possible
- Validation: Real-time validation of Sudoku rules (row, column, and 3x3 block constraints)
- Visual Feedback: Clear distinction between pre-filled and user-entered cells
- Backend: FastAPI (Python)
- Frontend: HTML5, CSS3, JavaScript (ES6+)
- Styling: Tailwind CSS
- Fonts: Inter (Google Fonts)
- Python 3.7+
- pip (Python package manager)
-
Clone or download the project files
# Ensure you have all these files in your project directory: # - main.py # - app.py # - index.html # - styles.css # - script.js
-
Install dependencies
pip install fastapi uvicorn
-
Run the application
uvicorn app:app --reload
-
Access the web interface
- Open your browser and navigate to
http://localhost:8000 - The web interface will load automatically
- Open your browser and navigate to
- Click "New Puzzle" to reset the board to empty state
- Use the board building or manual input methods to create your puzzle
- In the "Build Board" section, enter 81 digits (9 rows × 9 columns)
- Use
0for empty cells, digits1-9for filled cells - Format: Space or newline-separated digits
- Example input:
5 3 0 0 7 0 0 0 0 6 0 0 1 9 5 0 0 0 0 9 8 0 0 0 0 6 0 8 0 0 0 6 0 0 0 3 4 0 0 8 0 3 0 0 1 7 0 0 0 2 0 0 0 6 0 6 0 0 0 0 2 8 0 0 0 0 4 1 9 0 0 5 0 0 0 0 8 0 0 7 9 - Click "Build Board" to load the puzzle
- Click any cell on the board to select it (highlighted in blue)
- The row and column inputs will auto-populate
- Enter a digit (1-9) in the "Value" field
- Click "Insert Digit" to place the number
- Click "Delete Digit" to remove a number from the selected cell
- Click "Solve Puzzle" to automatically solve the current board
- The solver will:
- Find the unique solution (if one exists)
- Display "No solutions exist" if unsolvable
- Show multiple solutions if the puzzle is ambiguous
Run the standalone version:
python main.py- Start a new puzzle - Reset the board
- Build an entire board - Input 9 rows of 9 digits
- Insert a digit - Add a number to specific coordinates
- Delete a digit - Remove a number from specific coordinates
- Solve the puzzle - Run the automatic solver
- Quit - Exit the program
sudoku-solver/
├── main.py # Core game logic and CLI interface
├── app.py # FastAPI web server and API endpoints
├── index.html # Web interface structure
├── styles.css # Custom styling and board layout
├── script.js # Frontend JavaScript logic
└── README.md # This file
The FastAPI backend provides the following endpoints:
GET /- Serves the main web interfaceGET /styles.css- Serves the stylesheetGET /script.js- Serves the JavaScript filePOST /reset- Resets the game boardPOST /build- Builds a board from 9×9 arrayPOST /insert- Inserts a digit at specified positionPOST /delete- Deletes a digit at specified positionPOST /solve- Solves the current puzzle
Standard Sudoku rules apply:
- Grid: 9×9 grid divided into nine 3×3 sub-grids
- Numbers: Use digits 1-9 only
- Row Rule: Each row must contain each digit 1-9 exactly once
- Column Rule: Each column must contain each digit 1-9 exactly once
- Box Rule: Each 3×3 sub-grid must contain each digit 1-9 exactly once
The solver uses a backtracking algorithm:
- Find the first empty cell
- Try digits 1-9 in that cell
- Check if the digit violates Sudoku rules
- If valid, recursively solve the rest of the puzzle
- If no digit works, backtrack and try the next possibility
- Continue until solution is found or all possibilities are exhausted
"No solutions exist"
- Check that your input follows Sudoku rules
- Ensure no duplicate numbers in rows, columns, or 3×3 boxes
"Multiple solutions exist"
- The puzzle is under-constrained
- Add more clues to create a unique solution
Board won't build
- Verify you have exactly 81 digits
- Check that all digits are between 0-9
- Ensure no conflicts in the initial setup
Server won't start
- Verify FastAPI and uvicorn are installed
- Check that port 8000 is not in use
- Ensure all required files are in the same directory
To modify or extend the application:
- Backend changes: Edit
main.pyfor game logic,app.pyfor API endpoints - Frontend changes: Modify
index.htmlfor structure,styles.cssfor appearance,script.jsfor behavior - Testing: Use the command-line interface for debugging game logic
- Restart: Use
uvicorn app:app --reloadfor auto-reloading during development
Feel free to submit issues, fork the repository, and create pull requests for any improvements.
This project is open source and available under the MIT License.