A
Alex Raduca
Hi,
I am trying to solve the Sudoku Ruby Quiz using a 2d array of hashes
data model but I probably keep doing something wrong since the hashes
are referenced at row level(last row of the sudoku matrix is
referenced).
Could I get a hint on where I should insert the Hash.new when dealing
with 2d arrays. I have googled it but I could only find simple array of
hashes examples.
Thanks,
Alex
# creates sudoku matrix and fills it in with data
sudoku=Array.new(9,Array.new(9))
(0..8).each do |x|
(0..8).each do |y|
#load cell values into :values
sudoku[x][y]=Hash.new
print "load #{temp_ary[x][y]} in sudoku[#{x}][#{y}]\n"
sudoku[x][y][:value]=temp_ary[x][y]
#load possible solutions of this cell into ossibilities
if sudoku[x][y][:value]==0
sudoku[x][y][ossibilities]=[1,2,3,4,5,6,7,8,9]
end
end
end
I am trying to solve the Sudoku Ruby Quiz using a 2d array of hashes
data model but I probably keep doing something wrong since the hashes
are referenced at row level(last row of the sudoku matrix is
referenced).
Could I get a hint on where I should insert the Hash.new when dealing
with 2d arrays. I have googled it but I could only find simple array of
hashes examples.
Thanks,
Alex
# creates sudoku matrix and fills it in with data
sudoku=Array.new(9,Array.new(9))
(0..8).each do |x|
(0..8).each do |y|
#load cell values into :values
sudoku[x][y]=Hash.new
print "load #{temp_ary[x][y]} in sudoku[#{x}][#{y}]\n"
sudoku[x][y][:value]=temp_ary[x][y]
#load possible solutions of this cell into ossibilities
if sudoku[x][y][:value]==0
sudoku[x][y][ossibilities]=[1,2,3,4,5,6,7,8,9]
end
end
end