Class: SudokuResult
Instance Attribute Summary collapse
-
#depth ⇒ Object
readonly
Returns the value of attribute depth.
-
#forks ⇒ Object
readonly
Returns the value of attribute forks.
Instance Method Summary collapse
- #<<(sudoku) ⇒ Object
- #correct? ⇒ Boolean
- #each(&block) ⇒ Object
-
#initialize(depth) ⇒ SudokuResult
constructor
A new instance of SudokuResult.
- #many_solutions? ⇒ Boolean
- #merge(other) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(depth) ⇒ SudokuResult
Returns a new instance of SudokuResult.
11 12 13 14 15 |
# File 'lib/sudoku_result.rb', line 11 def initialize depth @results = [] @depth = depth @forks = 0 end |
Instance Attribute Details
#depth ⇒ Object (readonly)
Returns the value of attribute depth.
9 10 11 |
# File 'lib/sudoku_result.rb', line 9 def depth @depth end |
#forks ⇒ Object (readonly)
Returns the value of attribute forks.
9 10 11 |
# File 'lib/sudoku_result.rb', line 9 def forks @forks end |
Instance Method Details
#<<(sudoku) ⇒ Object
21 22 23 24 |
# File 'lib/sudoku_result.rb', line 21 def << sudoku @results << sudoku self end |
#correct? ⇒ Boolean
26 27 28 |
# File 'lib/sudoku_result.rb', line 26 def correct? @results.count == 1 end |
#each(&block) ⇒ Object
17 18 19 |
# File 'lib/sudoku_result.rb', line 17 def each &block @results.each &block end |
#many_solutions? ⇒ Boolean
30 31 32 |
# File 'lib/sudoku_result.rb', line 30 def many_solutions? @results.count > 1 end |
#merge(other) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/sudoku_result.rb', line 38 def merge other other.each do |sudoku| self.<< sudoku end @depth = [@depth, other.depth].max @forks += other.forks.succ end |
#to_s ⇒ Object
34 35 36 |
# File 'lib/sudoku_result.rb', line 34 def to_s @results.empty? ? '' : @results.first.to_s end |