Module: Xudoku
- Defined in:
- lib/xudoku.rb,
lib/xudoku/axis.rb,
lib/xudoku/board.rb,
lib/xudoku/utils.rb,
lib/xudoku/choice.rb,
lib/xudoku/solver.rb,
lib/xudoku/deducer.rb,
lib/xudoku/version.rb,
lib/xudoku/generator.rb,
lib/xudoku/formatter/base.rb,
lib/xudoku/formatter/json.rb,
lib/xudoku/formatter/array.rb,
lib/xudoku/formatter/string.rb
Overview
Xudoku is a Sudoku puzzle generator and solver.
The two main entry points are Xudoku.solve for solving an existing puzzle and Xudoku.generate for generating a new one. Both return an Result containing a matched puzzle and solution pair.
Solving a puzzle
result = Xudoku.solve("5 3 . . 7 . . . . ...")
puts result.puzzle # => the parsed board
puts result.solution # => the solved board
Generating a puzzle
result = Xudoku.generate
puts result.puzzle # => the puzzle with clues
puts result.solution # => the full solution
Defined Under Namespace
Modules: Axis, Formatter, Utils Classes: Board, Choice, Deducer, Error, Generator, Guess, Result, Solver
Constant Summary collapse
- VERSION =
"0.1.0"
Class Method Summary collapse
-
.generate ⇒ Result
Generates a new Sudoku puzzle and its solution.
-
.solve(input) ⇒ Result
Solves a Sudoku puzzle from a variety of input formats.
Class Method Details
.generate ⇒ Result
Generates a new Sudoku puzzle and its solution.
115 116 117 |
# File 'lib/xudoku.rb', line 115 def self.generate Generator.new.generate end |
.solve(input) ⇒ Result
Solves a Sudoku puzzle from a variety of input formats.
Accepts a string, array, or File object and delegates to the appropriate Board factory method. Returns a Result containing both the original puzzle board and its solution.
96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/xudoku.rb', line 96 def self.solve(input) board = case input when String Board.from_string(input) when Array Board.from_array(input) when File Board.from_string(input.read) end Result.new(puzzle: board, solution: Solver.new(board).solve) end |