Skip to content

Instantly share code, notes, and snippets.

@thomasfedb
Created May 10, 2010 12:33
Show Gist options
  • Save thomasfedb/395994 to your computer and use it in GitHub Desktop.
Save thomasfedb/395994 to your computer and use it in GitHub Desktop.
def hidden_singles
changed = false
@groups.each do |group|
numbers = []
group.each do |cell|
numbers = numbers + @possible[cell] unless @possible[cell].size == 1
end
(1..9).to_a.each do |number|
if numbers.count(number) == 1
# There is only one spot where number can go in this group. find it!
group.each do |cell|
if @possible[cell].member?(number)
@possible[cell] = [number]
@cell_groups[cell].each do |group|
@group_possible[group] = @group_possible[group] - @possible[cell]
@neiboughs[cell].each do |adjacent|
if @possible[adjacent].member?(@possible[cell])
@possible[adjacent] = @possible[adjacent] - @possible[cell]
end
end
end
changed = true
end
end
end
end
end
changed
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment