Created
February 25, 2014 02:59
-
-
Save tonyta/9201807 to your computer and use it in GitHub Desktop.
sudoku find unique
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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