G
Giant Cranes
Hi,
I have been learning ruby for the past week and am completely hooked.
Most of the code I am producing is elegant (ruby's credit), although I
am having trouble elegantly converting a single dimension array with 16
elements into a two-dimension grid [4x4].
Here is what I have so far:
@array = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]
@grid = Array.new
i = 0
index = 0
0.upto(3) do |i|
j = 0
0.upto(3) do |j|
@grid = Array.new if j == 0
@grid[j] = @array[index]
index += 1
j += 1
end
i += 1
end
@grid
Thanks,
Giant Cranes
I have been learning ruby for the past week and am completely hooked.
Most of the code I am producing is elegant (ruby's credit), although I
am having trouble elegantly converting a single dimension array with 16
elements into a two-dimension grid [4x4].
Here is what I have so far:
@array = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]
@grid = Array.new
i = 0
index = 0
0.upto(3) do |i|
j = 0
0.upto(3) do |j|
@grid = Array.new if j == 0
@grid[j] = @array[index]
index += 1
j += 1
end
i += 1
end
@grid
Thanks,
Giant Cranes