Sunday, April 22, 2007
Friday, April 20, 2007
Saturday, April 14, 2007
Thursday, April 12, 2007
Sudoku Solver
I've had this code laying around for a year, so I cleaned it up a little and decided to post it.
I work with people who like to solve logic puzzles. At some point we started doing the sudoku puzzles in the newspaper. After solving a few, it was obvious to us that they could be solved programmaticlly. This led to us trying to not just solve a single puzzle, but the meta-problem of solving sudoku puzzles in general. So we challenged each other to writing sudoku solvers. One person did his in Perl in a couple hours. I wrote mine in Python as a way to start learning the language. At the time it took me more than a couple hours, but I got it working. Every sudoku I could find can be solved in fractions of a second. Not long after that, Scientific American came out with an article on The Science behind Sudoku. The article has a puzzle with the minimum number of clues that still give a unique solution (17 clues). This puzzle is the only one I've found that actually takes some CPU cycles to solve. Needless to say, once we wrote the solvers, sudoku quickly lost its appeal.
My sudoku solver source file:
sudoku.python
Some input files:
easy
hard
diabolical
sciam 17 clue
I've had this code laying around for a year, so I cleaned it up a little and decided to post it.
I work with people who like to solve logic puzzles. At some point we started doing the sudoku puzzles in the newspaper. After solving a few, it was obvious to us that they could be solved programmaticlly. This led to us trying to not just solve a single puzzle, but the meta-problem of solving sudoku puzzles in general. So we challenged each other to writing sudoku solvers. One person did his in Perl in a couple hours. I wrote mine in Python as a way to start learning the language. At the time it took me more than a couple hours, but I got it working. Every sudoku I could find can be solved in fractions of a second. Not long after that, Scientific American came out with an article on The Science behind Sudoku. The article has a puzzle with the minimum number of clues that still give a unique solution (17 clues). This puzzle is the only one I've found that actually takes some CPU cycles to solve. Needless to say, once we wrote the solvers, sudoku quickly lost its appeal.
My sudoku solver source file:
sudoku.python
Some input files:
easy
hard
diabolical
sciam 17 clue
Sunday, April 08, 2007
Saturday, April 07, 2007
Friday, April 06, 2007
Wednesday, April 04, 2007
Sunday, March 25, 2007
Thursday, March 22, 2007
I recently starting listening to the NPR Sunday Puzzle podcast. I started listening to the oldest one I had from Jan 7. It had a challenge to find a 4x4 grid of 16 different letters, making four, four letter words across and four, four letter words down. As a hint the listener was told that the second row is the word 'ruly'. I worked on it briefly by hand and then decided to write a program to do it instead.
The code is basically a brute force search with a couple of short-circuits. I came up with a list of four letter words by taking a word list, grepping out all the four letter words, then adding all the three letter words with an 's' added (except the ones that ended in 's'). Not perfect, but close enough.
Python source: sundaypuzzle2007-01-07.py.txt
List of four letter words: four.txt
My answer below (select text to see):
bash
ruly
item
gown
gash
ruly
item
down
My answer matches the answer given in the Jan 21 show.
The code is basically a brute force search with a couple of short-circuits. I came up with a list of four letter words by taking a word list, grepping out all the four letter words, then adding all the three letter words with an 's' added (except the ones that ended in 's'). Not perfect, but close enough.
Python source: sundaypuzzle2007-01-07.py.txt
List of four letter words: four.txt
My answer below (select text to see):
bash
ruly
item
gown
gash
ruly
item
down
My answer matches the answer given in the Jan 21 show.
Sunday, March 18, 2007
Tuesday, March 13, 2007
Monday, March 12, 2007
Subscribe to:
Posts (Atom)


















