CodeNewbie Community 🌱

Cover image for Sudoku Solver - Solve Any Sudoku Puzzle Instantly
Dhruv Panchal
Dhruv Panchal

Posted on

Sudoku Solver - Solve Any Sudoku Puzzle Instantly

Why solve Sudoku by hand, when you can write script to solve them for ya ?!

Introduction:

  • Sudoku is one of the most popular logic-based number-placement puzzle game. The literal meaning of "Su-doku" in Japanese is "the number that is single".

  • The objective is to fill a nine-by-nine (9x9) grid with digits so that each row, column and 3x3 section contain number between 1 and 9, with each number used once and only once in each section. The Sudoku game players are provided with partially filled grid meant to be solved.

  • To solve sudoku one doesn't require the knowledge of mathematics but require the logic and reasoning. Solving Sudoku Puzzles daily helps with your brain. It improves the concentration and logical thinking. One can look for sudoku puzzles given in Newspapers or can play them online provided by many websites.

About:

This Script is a Sudoku Solver that solves almost any Sudoku Puzzle by visualizing through the Backtracking Algorithm which is made using the PyGame Library in Python. Ever tried but stucked on Sudoku Puzzles given in newspapers, magazines and online. You can use this script to get its solution instantly and move further.

GitHub logo dhhruv / Sudoku-Solver

🎯 This Python-based Sudoku Solver utilizes the PyGame Library and Backtracking Algorithm to visualize and solve Sudoku puzzles efficiently. With its intuitive interface, users can input and interact with the Sudoku board, allowing for a seamless solving experience.

Working:

  • Every time this Script is executed, a Random Solvable board is created.
  • Now, the user can first try to attempt solving it by clicking on the cells and entering values manually. Check the Input Section for the same.
  • Once the the user finalizes that the inputted number is the correct entry, pressing the enter key will attempt to input the number onto the board.
  • Correct answers will be permanently displayed while incorrect answers will be removed.
  • Likewise, values can be removed by pressing on the backspace or delete keys.

Entering Values GIF

  • If at any point the player decides to solve the board, the Spacebar key can be pressed.
  • This will commence a visual which will demonstrate how the backtracking algorithm works and how it is being applied in order to solve the board.

Visualizer GIF

Input:

Keys Actions
Left Click Selects the Box to enter a value into that cell.
Enter Confirms the Value written on the board.
Backspace/Delete Deletes the value in that cell.
Space Solves the Board using the Algorithm.
h Gives a Hint. Displays a random correct value on the board.

Requirements

In order to run the Script, the require Python & PyGame and you can install the requirements using:

pip install -r requirements.txt
Enter fullscreen mode Exit fullscreen mode

Execution:

  • Clone this repository using
git clone https://github.com/dhhruv/Sudoku-Solver.git
Enter fullscreen mode Exit fullscreen mode

OR
Zip Download the Repository and Extract it's contents.

  • Now run the SudokuGUI file directly in your Terminal using
python SudokuGUI.py
Enter fullscreen mode Exit fullscreen mode

OR

python3 SudokuGUI.py
Enter fullscreen mode Exit fullscreen mode

You can get more information about Sudoku Solver on:

GitHub logo dhhruv / Sudoku-Solver

🎯 This Python-based Sudoku Solver utilizes the PyGame Library and Backtracking Algorithm to visualize and solve Sudoku puzzles efficiently. With its intuitive interface, users can input and interact with the Sudoku board, allowing for a seamless solving experience.

Top comments (5)

Collapse
 
ellativity profile image
Ella (she/her/elle)

Why solve Sudoku by hand, when you can write script to solve them for ya ?

Because it completely defeats the object of Sudoku?

I'm not trying to take anything away from your post, or your script to solve it, but isn't the point of Sudoku to hurt my brain over and over? πŸ˜–

Collapse
 
dhhruv profile image
Dhruv Panchal

I just wanted to show how the backtracking algorithm works so I made it. And what you said is absolutely correct, Sudoku puzzles give the brain a hard time..πŸ˜‚

Collapse
 
ellativity profile image
Ella (she/her/elle)

Glad it's not just me putting myself through these headaches!

In all seriousness, @dhhruv , thanks for sharing! I really appreciate you taking the time to show us how you worked through this problem πŸ™

Thread Thread
 
dhhruv profile image
Dhruv Panchal

Yeah, you're not alone...

My Pleasure @ellativity , I was a #CodeNewbie at the beginning too so I know how important it is to present.

Collapse
 
kennykk2 profile image
KennyKK2 • Edited

I love games that are useful and not just make you waste your time. One of the most useful games I would call mahjong solitaire. I like this version of the game rather than the classic one. I am not bad at clearing the playing field in a very short time. Every time I improve my skill and I get better and better at it.