0

Hi all,
what is the best way to obtain all the possible 3-items groups out of 8 elements (0-7) with repetitions?
This would be D'8,3 = 8^3 = 512 groups. I want to save them in an array, like

unsigned int array[512][3];

What is the best approach?

2
Contributors
4
Replies
6
Views
7 Years
Discussion Span
Last Post by biswajit_cs07
0
    int array[][]=new int[512][3];
    int count=0;
    for(int i=0;i<8;i++)
        for(int j=0;j<8;j++)
            for(int k=0;k<8;k++){
                array[count][0]=i;
                array[count][1]=j;
                array[count][2]=k;
                count++;
            }
    for(int i=0;i<512;i++)
    {   System.out.print("array["+i+"]:");
        for(int j=0;j<3;j++)
        System.out.print(array[i][j]+" ");
        System.out.println("");
    }

Edited by mike_2000_17: Fixed formatting

Votes + Comments
Java? Thanks, but no thanks.
-3

In C:

unsigned int array[][]=new int[512][3];
int count=0;
int i,j,k;
for(i=0;i<8;i++)
for(j=0;j<8;j++)
for(k=0;k<8;k++){
array[count][0]=i;
array[count][1]=j;
array[count][2]=k;
count++;
}
for(i=0;i<512;i++)
{ 
   printf("\n array[%d]:",i);
   for(j=0;j<3;j++)
     printf("%d",array[i][j]);
}
Votes + Comments
We don't GIVE answers to problems, we help them find their own solutions.
0

Thanks for the reply biswajit_cs07, very appreciated.
PS: "new" operator doesn't exist in C. :)

0

Sorry I did not check the code. Just converted it from java to C without compilation.
Ya there is no new operator in C. If you know that you can easily rectify it.

Thanks.

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.