Skip to content

Instantly share code, notes, and snippets.

@tonyta
Created February 25, 2014 02:59
Show Gist options
  • Save tonyta/9201807 to your computer and use it in GitHub Desktop.
Save tonyta/9201807 to your computer and use it in GitHub Desktop.
sudoku find unique
def find_uniques
(1..9).each do |set_num|
map_unique( get_grid(set_num) )
end
end
def map_unique(set)
last_mapping = 'hello'
loop do
(1..9).each do |value|
val_count = 0
index = nil
set.each_with_index do |cell, cell_index|
if cell.is_a?(Array) && cell.include?(value)
val_count += 1
index = cell_index
end
end
set[index] = value if val_count == 1
val_count = 0
index = nil
end
break if last_mapping == set.join
last_mapping = set.join
end
set
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment