Wednesday, November 21, 2007

Sudoku Solver Progress

Decided to take a tentative stab at creating "the ultimate Sudoku Solving Program" (snort!) tonight. Wound up prototyping a function in Javascript that checks a solution candidate and returns true if it is valid or false if it is not valid. I know, using Javascript for the whole program would be lame, but for quick prototyping one function it wasn't too bad.

I'm actually pleasantly surprised how well it turned out. I pass the function an array, and voila!

It's funny, but the more I think about this, the more I realize I was wrong in my initial assumptions. This happens for me a lot-- I think I understand something, learn more about it and think about what I've learned, only to realize I was wrong and have to revise my understanding. Problem is, I was wrong in that means the program should be even easier/faster because there are fewer possibilities to sort through than I thought.

I originally stated that there were 81 cells with 9 possible variables, and then revised it downwards based on the average number of givens provided in a puzzle to something like 9 to the 53rd power. It's actually less than that.

Each row has to have the numbers 1 through 9, with no repeats. It's not 81 cells with 9 possible variables- it's a subset of that because each row and column must be a combination of the digits 1 through 9*. I have no idea how to represent that mathematically, but I'm pretty sure that brings the number of total possibilities down considerably.

* for example: 123456789, 234567891, 345678912, etc. but never 111111111, 111111112, etc.