4 ms·
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!
by dhotson 19y ago
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 19y agoPeter 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 http://norvig.com/sudoku.html
- nazgulnarsil 19y agoglad 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 19y agoHmm.. 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 19y agoI'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.