Jeremy Stein - Journal
« Dog Chase | The sone of earth » |
Sudoku solver in Python
I recently learned about Sudoku puzzles. I solved one, but after that it seemed a more interesting problem would be to write a computer program to solve them.
I’ve also long wanted to play with Python. So, here is my first Python program: an inefficient Sudoku solver
(Sudoku is a well-researched problem and there are already open-source implementations using Donald Knuth‘s lightning-fast dancing links algorithm. In contrast, this code maps to the way my brain solves these puzzles.)
If you have any Python experience, I’d appreciate any feedback. In particular, I couldn’t figure out how to get the sole member of a set. I created a method (singleValue) to do it for me because I needed it in several places.
3 Comments
- Drew Sutherland replied:
Hello,
I recently created my own sudoku-solver in python. I was pretty pleased with myself because my python experience isnt extensive and I thought I was the only one to do it (until I googled – now I know Im definitely not the only one).
My algorithm was made-up by myself too and it definitely isnt optimal. Nonetheless, my next task was to put it on the web. Have you thought about doing this? Have you thought about a small interface embedded in the html to allow poeple to enter and solve then and there? Im experimenting with python to php generators but havent really got my teeth into it yet.
I just copied and pasted your code but it has a problem with line 36 and the ‘set’ at runtime?
Drew
February 6th, 2006 at 3:33 pm. Permalink.
- Jeremy replied:
Save the file as “sudoku.py”. Run this command:
python sudoku.py
I’m running python 2.4.2.
February 10th, 2006 at 11:25 pm. Permalink.
- Tara Stein replied:
Ignore this test comment.
f1
November 11th, 2007 at 8:16 am. Permalink.
Leave a Reply