Introducing: Sudoku

14 Aug 2006

So last night I got this bright idea to create my own Sudoku generator. The first iteration it randomly generated the first row and for each row after that it kept generating random arrays until they fit. This worked for some cases but failed more times that not. In addition processing time became an issue.

I then tried to create the puzzles using a brute force methodology. This worked but I noticed that some 3x3 sections were not correct or had repeating numbers.

Finally, I created a loop and a method that seemed to work. There were however occasions (not sure why I think it has to do with some inconsistencies in PHP) where it would fail. So, I built a simple row check that told the program to re-run itself when it failed. The result a simple PHP class that generates Sudoku puzzles in record time. It uses recursion to eliminate certain rows combinations.

I've posted the puzzle page for printing... I'm working on a web based puzzle version. I also posted a debug version that shows the algorithm step by step... the max number of re-runs I've seen is five if your playing with it and see more than that I would love to know.

Enjoy...

Sudoku Puzzle Generator