Hi all.
I need to load an array with 10 numbers, and place the sum in another
array of numbers as follows: number [0] + number [9], number [1] +
number [8] and so on. Overall I have to have the following COMBINATIONS:
0+9
1+8
2+7
3+6
4+5
5+4
6+3
7+2
8+1
9+0
This is the code that was doing:
···
##################################################
srand
rating=[]
result=[]
aux=[]
n=10
for i in 0..n-1
rating[i]=rand(10)+1
end
for i in 4..n-1
aux[i]=rating[i]
end
aux.reverse!
for i in 0..n-1
result[i]=rating[i]+aux[i]
end
puts "#{rating}"
puts "#{result}"
###########################################
Up to half of the array works fine, but after following values
generates bad.
Thanks.
--
Posted via http://www.ruby-forum.com/.