SUDOKU SOLVER
SUDOKU SOLVER
1. What is Sudoku?
Sudoku is a logic-based, combinatorial number-placement puzzle also called as Number place. In classic sudoku, the objective is to fill a 9×9 grid with digits so that each column, each row, and each of the nine 3×3 subgrids that compose the grid (also called "boxes", "blocks", or "regions") contains all of the digits from 1 to 9. The puzzle setter provides a partially completed grid, which for a well-posed puzzle has a single solution.
Sudoku has many variations of grid sizes or region shapes and all. Also, it has many types in it some are mentioned below:
- Killer Sudoku
- Alphabetical Sudoku
- Hyper Sudoku / Windoku
- Twin Sudoku
2. Algorithm Used for our Sudoku Solver.
2.1 What is Backtracking?
Some hobbyists have developed computer programs that will solve Sudoku puzzles using a backtracking algorithm, which is a type of brute force search. Backtracking is a depth-first search (in contrast to a breadth-first search), because it will completely explore one branch to a possible solution before moving to another branch. Although it has been established that approximately 5.96 x 1126 final grids exist, a brute force algorithm can be a practical method to solve Sudoku puzzles.
A brute force algorithm visits the empty cells in some order, filling in digits sequentially, or backtracking when the number is found to be not valid. Briefly, a program would solve a puzzle by placing the digit "1" in the first cell and checking if it is allowed to be there. If there are no violations (checking row, column, and box constraints) then the algorithm advances to the next cell and places a "1" in that cell. When checking for violations, if it is discovered that the "1" is not allowed, the value is advanced to "2". If a cell is discovered where none of the 9 digits is allowed, then the algorithm leaves that cell blank and moves back to the previous cell. The value in that cell is then incremented by one. This is repeated until the allowed value in the last (81st) cell is discovered.
The animation shows how a Sudoku is solved with this method. The puzzle's clues (red numbers) remain fixed while the algorithm tests each unsolved cell with a possible solution. Notice that the algorithm may discard all the previously tested values if it finds the existing set does not fulfil the constraints of the Sudoku.
Advantages of this method are:
- A solution is guaranteed (as long as the puzzle is valid).
- Solving time is mostly unrelated to degree of difficulty.
- The algorithm (and therefore the program code) is simpler than other algorithms, especially compared to strong algorithms that ensure a solution to the most difficult puzzles.
The disadvantage of this method is that the solving time may be slow compared to algorithms modeled after deductive methods. One programmer reported that such an algorithm may typically require as few as 15,000 cycles, or as many as 900,000 cycles to solve a Sudoku, each cycle being the change in position of a "pointer" as it moves through the cells of a Sudoku.
3. Code for solving Sudoku using Backtracking:
4. Complete code in Python for Sudoku Solver GUI:
5. Conclusion :
6. References:
- https://en.wikipedia.org/wiki/Sudoku
- https://en.wikipedia.org/wiki/Backtracking
- https://en.wikipedia.org/wiki/Sudoku_solving_algorithms

good work
ReplyDeleteGreat work Aditya
ReplyDeleteAmazing explanation
ReplyDeleteGreat 👍
ReplyDeleteInformative..!
ReplyDeleteAmazing 👍
ReplyDeleteVery nice information 👍👍👌👌
ReplyDelete