I am trying to make a pair of symmetrical arrays, but am stumped as to the method to achieve them. I will show first what I am going for.
[ 0.125, 0.25, 0.5, 1.0, 1.0, 1.0, 1.0]
[ 0 , 0 , 0 , 0, 0.5, 0.75, 0.875 ]
The top array is the result of the below code, with three 1s added to it:
var number_of_changes = 4;
number_of_changes.collect{|i| 2.pow(i).reciprocal}.reverse;
The bottom array is the same as the top, if it were reversed, and the values subtracting from 1.
There are two barriers in my mind.
The first is that the array is not double the length of “number_of_changes” but double minus one.
The second issue is I have no elegant method (or even a crude one) for adding the additional “number_of_changes-1” values to the result of:
number_of_changes.collect{|i| 2.pow(i).reciprocal}.reverse;
I have only been able to generate this array so far:
[ 0.125, 0.25, 0.5, 1.0 ]
The two things I would like to do therefore are to create the longer array, and then create its symmetrical twin array that I described above.
Any help on this without be gratefully received.