0

Hi,
In the code below I have 2 nested loops, with the inner loop starts from the index of the outer loop till the end. You can think of it as I am trying to find ll the combinations. So if we have 'm' rows, we will have m(m+1)/2 possible combination. I want to map 'i' & 'g' to indices that covers that range starting from 0 to ( (m(m+1)/2) - 1).

const int m = 5;
int arr[m(m+1)/2];  
for( int g = 0; g < m; g++)
{
    for(int i = g; i < m; i++)
    {
        // we have here 15 possible combination, index should start from 0 to 14
        // and i want to deduce index from i,g and m
        arr[index] = index;
    }
}

I know that this is a mathmatical problem more than a problem in coding but I am looking for your help
thanks!

2
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by salah_saleh
0

if g = 0 then i can range from 0 to m
if g = 1 then i can range from 1 to m
...
if g = (m-1) then i can range from (m-1) to m

What I am trying to get at is, you cannot get a unique mapping with just 'i' and 'g'.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.