05-23-2003, 12:25 AM
I don't know if I should post this as a "challenge" or in the "programming help" section...anyway...here it is. What I want to do is to take 2 arrays and interleave them, so that the values from each array are (approxamately) evenly distributed in a third array. I know how to do this, but want to know if anyone has a more elegant way. My method is to create a new array sized the sum of size of the 2 original arrays. Then, this array is filled with alternating chuncks from each array. The size of the chunk is determined by dividing the larger array by the smaller then inserting the whole number followed by a single element from the smaller array.
if, for example, array1 contained 3 elements elements: x,x,x
and arrat2 contained 11 elements: a,a,a,a,a,a,a,a,a,a,a
My method produces a third array containing:
aaaxaaaaxaaaax
I would like to have the elements more evenly distributed, for example: aaxaaaxaaaxaaa
Does anyone see an efficient way to do this?
Thanks. The following snippet should get us started on the same page...
Thanks
if, for example, array1 contained 3 elements elements: x,x,x
and arrat2 contained 11 elements: a,a,a,a,a,a,a,a,a,a,a
My method produces a third array containing:
aaaxaaaaxaaaax
I would like to have the elements more evenly distributed, for example: aaxaaaxaaaxaaa
Does anyone see an efficient way to do this?
Thanks. The following snippet should get us started on the same page...
Code:
'INPUT "Number of elements in Array 1";s1
'Input "Range for values in array 1 (0 to ?)";r1
'Input "Number of elements in Array 2";s2
'input "range for values in array 2 (0 to ?)";r2
s1=100 'array1...100 elements between 0 and 5
r1=5
s2=20 'array2...20 elements between 0 and 30
r2=30
dim array1(1 to s1) as integer
dim array2(1 to s2) as integer
for x=1 to s1
array1(x)=rnd*r1 'fill array1 with values
next x
for x=1 to s2 'fill array2 with values
array2(x)=rnd*r2
next x
DIM array3(1 TO (UBOUND(a)-LBOUND(a))+(UBOUND(b)-LBOUND(b))) AS INTEGER
'How to fill array3 with interleaved elements of array1 and array2???
Thanks