Loop through different sets of unique permutations

Posted by user558610 on Stack Overflow See other posts from Stack Overflow or by user558610
Published on 2010-12-31T05:50:43Z Indexed on 2010/12/31 5:53 UTC
Read the original article Hit count: 137

Filed under:
|
|

Hi

I'm having a hard time getting started to layout code for this problem.

I have a fixed amount of random numbers, in this case 8 numbers. R[] = { 1, 2, 3, 4, 5, 6, 7, 8 };

That are going to be placed in 3 sets of numbers, with the only constraint that each set contain minimum one value, and each value can only be used once.

For example:

R1[] = { 1, 4 }

R2[] = { 2, 8, 5, 6 }

R3[] = { 7, 4 }

I need to loop through all possible combinations of a set R1, R2, R3. Order is not important, so if the above example happened, I don't need

R1[] = { 4, 1 }

R2[] = { 2, 8, 5, 6 }

R3[] = { 7, 4 }

NOR

R1[] = { 2, 8, 5, 6 }

R2[] = { 7, 4 }

R3[] = { 1, 4 }

What is a good method?

© Stack Overflow or respective owner

Related posts about algorithm

Related posts about loops