Sunday, December 2, 2007

Sudoku Solver, revisited

I put aside the "killer sudoku solver" project for a few days. It was a nice diversion during the Thanksgiving holiday weekend, but it consumed far too many hours and mental energy.

But, now that I've got some more time on my hands, I find my thoughts returning to it again. I did some reading up on regular expressions, and I've come away more convinced than ever that a dictionary-attach approach to Sudoku puzzles is still the best way to handle it. There are a finite number of possible valid Sudoku puzzles. If I can capture them all in a simple text file, then it's just a matter of running a tool like grep with a regular expression against the text file, and voila!

Since my original file of 362880 lines with nine characters per line comes in at about 3.5 MB, I assumed a full "Sudoku dictionary" of 81 characters per line would come in at well over 30 MB. Since I haven't figured out a way to reliably generate only valid combinations, I can only begin to guess at the size of the final product. The overall length of each line is increasing to nine times its original size, but I'm not sure that some lines won't be eliminated entirely by the logistics of the puzzle structure itself.