Class: Namero::SolverExtensions::CandidateExistsOnlyOnePlace
- Inherits:
-
Object
- Object
- Namero::SolverExtensions::CandidateExistsOnlyOnePlace
- Defined in:
- lib/namero/solver_extensions.rb
Overview
If a candidate number exists only one place in an affected group, we can fill the box. For example:
When candidates are: [1 2 3] [2 3] [1 2 3] [1 2 3 4]
The last box's value is 4 because there is 4 candidate only the last box.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(board, queue) ⇒ CandidateExistsOnlyOnePlace
constructor
A new instance of CandidateExistsOnlyOnePlace.
- #solve ⇒ Object
Constructor Details
#initialize(board, queue) ⇒ CandidateExistsOnlyOnePlace
Returns a new instance of CandidateExistsOnlyOnePlace.
13 14 15 16 |
# File 'lib/namero/solver_extensions.rb', line 13 def initialize(board, queue) @board = board @queue = queue end |
Class Method Details
.solve(board, queue) ⇒ Object
9 10 11 |
# File 'lib/namero/solver_extensions.rb', line 9 def self.solve(board, queue) self.new(board, queue).solve end |
Instance Method Details
#solve ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/namero/solver_extensions.rb', line 18 def solve board.each_affected_group do |group| (1..n).each do |v| box = nil group.each do |value| if !value.value && value.candidates.include?(v) if box box = nil break else box = value end end end if box box.candidates = [v] queue << box.index end end end end |