Wednesday, September 12, 2007

Sudoku Excel solver

I am a numbers kind of guy; and I have enjoyed the Sudoku craze. But I am also an Excel spreadsheet kind of guy, and have often boasted that I can make Excel do anything I want. Then I began to wonder if I could make an Excel work book that can solve Soduko puzzles. Yes I can!

I created a sheet that has a grid for the puzzle you are trying to solve, and then another grid next to it that shows recommended moves. As you enter the recommended moves into the puzzle grid, other recommended moves are generated. The recommendations come from four different sources. One is that the particular move is the only place in that column where that number can go, another is the only place in that row for that number to go, and another is the only place in that 3 by 3 big square for that number to go. The fourth source of recommendations is that that small square cannot hold any of the other eight numbers, and therefore must be the recommended number.

The Excel spreadsheet NEVER misses seeing any easy, available move. It is amazing how many moves it points out to me, that I did not see when looking at the same puzzle.

What the spreadsheet still cannot do, is realize that when a pair of numbers must both go into a pair of spaces, those spaces would be off limits for any other number. And it does not have the ability to realize that when a number is going to be forced into two or three spots all inside the same big square, it will make it impossible for that number to go into any other square in that big square. But those situations do not come up as often, when you never miss an "obvious" move.

The most amazing part for me, is that I was able to do this using Excel - which is not even a regular programming language!

1 comment:

Ahmed A. Khan said...

I am intrigued by your post, John. I am a Sudoku fan and would love to have a look at your spreadsheet. Would it be possible to email it to me - khan dot ahmeda at gmail dot com?