You are on page 1of 4

Sudoku Solver

I used this as an excuse to learn Python.  Going through examples is one way to learn but
doing a project is even better.  My grandpa always sits around solving Sudoku which bleed into
his grandkids.  I grew up solving these puzzles and when it came to learning Python, making an
automatic solver seemed like the obvious choice.  When I am finished it, I had to show my
grandpa and race hit in solving a puzzle.  Needless to say, even with his years of experience and
tricks that I do not know about, my program was able to beat him.  The first thing that I had to
accomplish is what to do with the blank spaces.  My solution was making those equal to 0.

Figure 1. Inputted Puzzle

Now that I had the base, it was time to solve. I recursively solved the system. Starting at
the top left if the value was a 0, it then added a 1 to that location.

Figure 2. Staring point


Figure 3. Add 1

Once it added the one, it would check to see if the one violated the rules of Sudoku. If it
did, then it would increment by one.

Figure 4. Violation

Figure 5. increase

If it passed, then it would move to the right following the same column but to the next
row. It would then repeat the process of starting at one, and counting up to 9.
Figure 5. increase

Figure 5. increase

If no value would work inside of that square, it would then go back one and increment
that by one.

Figure 6. Back Tracking

It will continue this trend until the whole table is solved.


Figure 7. Final Solution

It will continue this trend until the whole table is solved.

Ways to improve and what is to come


The first thing that I think about when trying to solve this problem is that there must be
more efficient ways. The key with this, is that I used the onboard system clock to measure how
long it takes to solve the problem. The longest that I have seen was 1 minute and 24 seconds
with the average being around 40 seconds. With this being so fast, I do not see the need to speed
it up using the typical methods used to solve sudoku.
The next improvement that I am going to make is to add a GUI. You must input the
puzzle straight into the code and I want to make it easier to implement new code. To accomplish
this, I am going to have a popup window with a blank puzzle. You can then input only the
values that are used to start the puzzle.

You might also like