

Sudoku in 201 lines - dhotson
http://pastie.caboo.se/172637
I got bored at work and had a go at a sudoku solver in Ruby. It can solve most medium difficulty puzzles.
Any tips on improving my code would be appreciated!
======
jws
I should have read the comment before the code. I was just coming to the
conclusion that the code could not solve the harder sudokus.

The wikipedia article on "Algorithmics of Sudoku" is a start for tips. There
is a Scientific American article that has a good overview of the problem...
[http://www.cs.utexas.edu/~kuipers/readings/Sudoku-
sciam-06.p...](http://www.cs.utexas.edu/~kuipers/readings/Sudoku-sciam-06.pdf)

Don't google for Lispers writing solvers. They will make you feel all bloated.

------
dhotson
I got bored at work and had a go at a sudoku solver in Ruby. It can solve most
medium difficulty puzzles. Any tips on improving my code would be appreciated!

~~~
marcus
Peter Norvig's solution is more elegant (he just brute forces it), it works on
all puzzles and is just 100 lines of Python

<http://norvig.com/sudoku.html>

~~~
nazgulnarsil
glad someone mentioned it. there is no point in NOT brute forcing a problem
such as this when it doesn't really take all that much brute force to begin
with. What good is a sudoku solving algorithm? Algorithm's are to eliminate
the need for brute force when brute force would take too long/require too much
resources.

~~~
dhotson
Hmm.. good point. I didn't really consider brute force to be viable. Is it
actually necessary on some of the harder puzzles? Or can they be deduced
solely using logic and without 'guessing'?

~~~
nazgulnarsil
I'm not positive because I don't really play the puzzles a lot. But i think
some of them require mentally filling in a space and seeing if it leads to a
contradiction.

