Ruby Solver

Programs which generate, solve, and analyze Sudoku puzzles

Ruby Solver

Postby blinks » Thu Nov 10, 2005 4:03 am

I've written a solver (couldn't help myself after learning the rules) that basically solves using 'pencil marks.'

The code is here: http://blinkinblogs.net/~blinks/sudoku.rb

It's written in Ruby (if you're on *nix you can chmod a+x it) and takes one file as an argument (on Windows, if you have Ruby installed, you might be able to drag the puzzle file into it... but I'm not sure...). This file is of the following format:
Code: Select all
1???????9
?6?8?7?5?
??7???2??
21??5??93
???4?8???
43??2??87
??1???9??
?5?6?9?4?
6???????8

(just the puzzle with ?s where the unknowns are)

If anyone's interested, I'll describe the algorithm. It's optimized (I used Ruby's profiler and made it 3x faster than the original version), and will solve any simple puzzle.

I was thinking about including a brute force method to make it solve any puzzle, but the official rules state that you shouldn't have to guess, and so I held off.

Comments? Questions?
blinks
 
Posts: 1
Joined: 09 November 2005

Return to Software

cron