Solves traditional square Sudoku puzzles
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib
test
.document
.gitignore
MIT-LICENSE
README.rdoc
Rakefile

README.rdoc

sudoku

Solves traditional square Sudoku puzzles

See en.wikipedia.org/wiki/Sudoku

Usage

board = [
  [  2, nil, nil, nil, nil,   1, nil,   3,   8],
  [nil, nil, nil, nil, nil, nil, nil, nil,   5],
  [nil,   7, nil, nil, nil,   6, nil, nil, nil],
  [nil, nil, nil, nil, nil, nil, nil,   1,   3],
  [nil,   9,   8,   1, nil, nil,   2,   5,   7],
  [  3,   1, nil, nil, nil, nil,   8, nil, nil],
  [  9, nil, nil,   8, nil, nil, nil,   2, nil],
  [nil,   5, nil, nil,   6,   9,   7,   8,   4],
  [  4, nil, nil,   2,   5, nil, nil, nil, nil]
]

sudoku = Sudoku::Puzzle.new(board, :blank => '.')

puts sudoku.puzzle
# 2 . . . . 1 . 3 8
# . . . . . . . . 5
# . 7 . . . 6 . . .
# . . . . . . . 1 3
# . 9 8 1 . . 2 5 7
# 3 1 . . . . 8 . .
# 9 . . 8 . . . 2 .
# . 5 . . 6 9 7 8 4
# 4 . . 2 5 . . . .

puts sudoku.solve!.puzzle
# 2 4 9 5 7 1 6 3 8
# 8 6 1 4 3 2 9 7 5
# 5 7 3 9 8 6 1 4 2
# 7 2 5 6 9 8 4 1 3
# 6 9 8 1 4 3 2 5 7
# 3 1 4 7 2 5 8 6 9
# 9 3 7 8 1 4 5 2 6
# 1 5 2 3 6 9 7 8 4
# 4 8 6 2 5 7 3 9 1

TODO

  • Finish tests

  • Look into failures with default solver

Note on Patches/Pull Requests

  • Fork the project.

  • Make your feature addition or bug fix.

  • Add tests for it. This is important so I don't break it in a future version unintentionally.

  • Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but

    bump version in a commit by itself I can ignore when I pull)
  • Send me a pull request. Bonus points for topic branches.

Copyright

Copyright © 2009 Sean Huber. See MIT-LICENSE for details.