Saturday, January 14, 2006

Sudoku

Here is a post that's slightly different but the technical ones out there (which at this point I think is all of you) may enjoy it.
It's about Sudoku (which if you haven't heard of - go do a quick google search on it.
(A side note: I'm not so sure why Sudoku, of all logic puzzles, has become so popular - but that's a subject for a different post)
As a programmer, the first thought you have (OK maybe not THE first, but at lest on of the first ) when seeing a game like Sudoku is how hard it would be to write a program to solve such a puzzle.
Of course, with a little thought you realize that to solve Sudoku wouldn't be that hard. It's not much more then the famous Eight Queens Puzzle we all learned in one of our first data structure classes. It's nothing that a nice recursive algorithm couldn't solve. But this is just your basic brute force approach.
The more interesting thing is to write a program that solves the puzzle logically. This would be much more challenging to write and helpful to a person trying to solve the a problem and is looking for a little help.
At most the brute force approach will be able to do is figure out the solution and then give hints to the solver by filling in squares for him. But the solver will learn nothing from this.
What would be much more useful is a program that dynamically solves and figures out the next logical move to the puzzle and explains to the user why it's a good move.
One of the best examples, I have seen of this is in a game called FathomIt (created by Har Nof's Moshe Rubin which some of you may know) which is a pretty good solitaire puzzle game. But what makes it great is the solver which does exactly that (i.e. logically explains what your next move shoud be and why.)
So, in my spare time, I have started working on a program that will do exactly that for Sudoku. (Of course my spare time seems to be somewhere around a half an hour a week - so I am not progressing too fast :-) )
The other reason (and probably the real reason) I am doing this is as an excuse to learn a new programming language called Ruby. (More on Ruby another time)
So, since I am trying to learn Ruby at the same time, it is really going slow.
But to quote from a well known source "Life's a journey, not a destination".

No comments: