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!

Recommended Answers

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 …

Jump to Post

All 2 Replies

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'.

Then is there anything we can add to 'i & 'g' to get a unique mapping?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.