Class: Namero::Solver

Inherits:
Object
  • Object
show all
Defined in:
lib/namero/solver.rb

Instance Method Summary collapse

Constructor Details

#initialize(board, extensions: []) ⇒ Solver

Returns a new instance of Solver.



5
6
7
8
9
# File 'lib/namero/solver.rb', line 5

def initialize(board, extensions: [])
  @board = board
  @updated_candidate_queue = Set.new
  @extensions = extensions
end

Instance Method Details

#solveObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/namero/solver.rb', line 11

def solve
  fill_candidates
  loop do
    idx = updated_candidate_queue.first
    unless idx
      extensions.each do |ex|
        ex.solve(board, updated_candidate_queue)
      end
      break if updated_candidate_queue.empty?
      next
    end
    @updated_candidate_queue.delete idx
    fill_one_candidate(idx)
  end
end