|
|
What is the back-tracking algorithm?
1. First of all check each square in turn for the number of possible numbers that could be in that position, by eliminating the other numbers that are given in the same row, column and 3x3 grid.
2. Then starting at the first unknown square we'll try with the lowest available number that is allowed.
3.Move on to the next square then we'll try with the lowest available number...and keep doing this.
4. If you hit a problem and there are no available numbers then move back a square [i.e. you must `back-track'], and increase that digit to be the next lowest available number. Go to step 3.
5. Eventually you should pass through all the squares in the grid - and `voila' you have the solution!
Note you may end up having to back-track all the way back to the beginning several times! However, a computer can do this easily and reasonably quickly.
We wrote this program in R fairly quickly and it seems to do the job. Making it work faster is more of a challenge - that's left for another day. Also, working out how many solutions a Sudoku grid has is not so straightforward - again on the back burner for now.
If you're interested in using this more than a few times then you ought to download R (see cran.r-project.org ) and install it on your machine (it's free!), then source in this R code . There is absolutely no warranty and the Licence is GPL2. We should warn you that you probably need to be familiar with R to do this - or at least be a bit of a boffin. There's another challenge for you!
One nice by-product is that the program gives you the number of possibilities at the outset for each square, which can be a helpful way to start a difficult puzzle if you're stuck.
All puzzles on this site have been checked using this program.