As i think my problem is a mathematical one I post it here, if I should be somewhere else please tell me where.
I have a multiple array (5 or 6 dimensions each being of same size) where only elements with different indexcombinations are being filled (i.e. if element [1,2,3,4,5,6] being filled element [6,5,4,3,2,1] will NOT be filled) so I want to store all elements of such a multiple array in a lineairarray and compute the indexes for each element as it saves a lot of memory.
N = 20; // maximum number of an element in each dimension
MaxIndex= N * ((N+1)/2) * ((N+2)/3) * ((N+3)/4) * ((N+4)/5) * ((N+5)/6);
long Array = new long [MaxIndex];
Index=0;// Index in the array
for (i1=0; i1<N; i++)
for (i2=0; i2<N+1; i++)
for (i3=0; i3<N+3; i++)
for (i4=0; i4<N+4; i++)
for (i5=0; i5<N+5; i++)
for (i6=0; i6<N+6; i++)
Array[Index++] = <something>;
How can I calculate the index of ANY element in Array given values for i1, i2, i3, i4, i5, i6 ?
for a 2 dimensional array I know the formule
i2 + i1 * N - (i1 * (i1+1) / 2);
I'm looking for something similar for multiple dimensions
Thanks for any help in advance