Friday, June 24, 2005

Su-Doku Solver

I was first introduced to Su-Doku a few days back by my friends Sujit and Addy. It was a daily feature in one of the newspapers: The Hindu. It is a placement puzzle and each puzzle could have only one solution. I could do the puzzles but it took me around 1/2 an hour to finish them. Now, this is good if you want to kill time and it helped me during the long tiring train journey from Cochin to Delhi in June 2005. On the train I was wondering that it would be pretty easy to write a program which solves the puzzle.


When I reached Delhi I started learning Python, mainly because the language intrigued me and there were a lot of people ( Eric. S. Raymond and Bruce Eckel to name a few ) had given it a thumbs up. Now it has been around 3 days since I started learning it and I must say it is a beautiful language in it's own rights.


So, I wrote a Su-Doku puzzle solver today in the evening of 24th June because it was too hot outside and I wanted to learn python.


Here is the python code. I have just used two test cases for it, which can be found here and here.

[update 25th June] The solver is in fact broken. I guess I should have used more test cases. It solves easy puzzles but gets stuck in some of the medium to hard puzzles. I will try to get it working for them also.

[update 25th June]Took care of the problem. Now it is solving the hard and medium puzzles also. I will feed it some more test cases before announcing success.

No comments: