Class: Sudoku::SolutionSet::Process::Steps::PickChoiceSatisfyingConstraint

Inherits:
Sudoku::SolutionSet::Process::Step show all
Defined in:
lib/sudoku/solution_set/process/steps/pick_choice_satisfying_constraint.rb

Instance Attribute Summary

Attributes inherited from Sudoku::SolutionSet::Process::Step

#output

Instance Method Summary collapse

Methods inherited from Sudoku::SolutionSet::Process::Step

#constraints, #delete_excluded_choices_if, #exclude_choice, #excluded_choices, #include_choice, #included_choices, #initialize, #restore_excluded_choices, #retry?, #revert, #take

Constructor Details

This class inherits a constructor from Sudoku::SolutionSet::Process::Step

Instance Method Details

#revert!Object



18
19
# File 'lib/sudoku/solution_set/process/steps/pick_choice_satisfying_constraint.rb', line 18

def revert!
end

#take!(constraint) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/sudoku/solution_set/process/steps/pick_choice_satisfying_constraint.rb', line 6

def take!(constraint)
  candidates = excluded_choices.select { |excluded_choice|
    constraint.satisfied_by?(excluded_choice)
  }

  if retry?
    candidates.slice!(0..candidates.index(output))
  end

  candidates.first
end