Skip to content

Sudoku Solver project using backtracking that takes input as a nested list and solves the Sudoku. Updated version uses PyAutoGUI and solve Sudokus on the internet.

Notifications You must be signed in to change notification settings

Shamitr-Mardikar/SudokuSolver

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 

Repository files navigation

Sudoku Solver using Backtracking in Python.

As a human being, we use the following steps to solve a sudoku. Let us consider the number that we're checking for to be the selected number "N" in this case.

The steps you would follow would be

  • To check if N is in the column that you're in.
  • To check if N is in the row that you're in.
  • Finally, check if N is in the 3x3 bordered box that you're in.

However, the approach to this problem is a little bit different in programming to reference, you can check demonstration.py. The diagram below could help you understand this a little better.

Screenshot 2024-03-08 at 10 57 49 PM

The approach we take in Python would be as follows :

  • First, we write a function that inputs the selected Number "N", its X axis, and its Y axis. Next, it goes on to check if the current X-axis parameter has N or not. It proceeds to do the same with the Y-axis parameter as well. However one has to keep in mind that while checking the X-axis, the Y-axis isn't the same as the value you are iterating with, and the same goes for iterating through the Y-axis. Because this would lead to an edge case where it would coincide with the N value itself and return False.
  • Next, we have to write a function to check inside the 3x3 Box. Here, we take a very specific and cunning approach to the problem. We first take the 3x3 Box based on the current axes that N is in. Next, we do [(X-Axis or Y-Axis // 3) * 3]. The operation provides us the diagonal left top index from where we have to iterate inside the 3x3 box to check if any value has the same value as N.

Finally, after finishing the approach, we write a display function to display the solved Sudoku.

The demonstration file however requires a nested list as the input Sudoku to work off. I'm currently working on a Pyautogui program so that the code can also work on sudokus on the internet.

About

Sudoku Solver project using backtracking that takes input as a nested list and solves the Sudoku. Updated version uses PyAutoGUI and solve Sudokus on the internet.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages