Click to See Complete Forum and Search --> : Display all possible combinations (from a pair of combinations)


arrplayr
February 5th, 2009, 12:28 PM
Hi all,

I am sorry if this was asked before but I dont know how to mathematically describe what I need, hence, how to ask for solution. I will post an example of the wanted result, and HOPE that someone will point me to the right direction:

I have the following table:
1; X
2; Y
3; Z

There are 8 combinations in this example and I need to list all of them something like this:

1. 1, 2, 3
2. 1, Y, 3
3. 1, Y, Z
4. 1, 2, Z
5. X, 2, 3
6. X, Y, 3
7. X, Y, Z
8. X, 2, Z

If you don't have the algorithm, please give me some terminology that I can use to research the problem.

Thanks !

Peter_B
February 7th, 2009, 01:49 PM
This is the exact same problem as in this thread (http://www.codeguru.com/forum/showthread.php?t=469910) except that the symbols used are different. That thread uses 0 and 1 for the two symbols for each of the 3 pairs, whereas you are using 1,2,3,X,Y and Z.

There are 8 combinations in this example and I need to list all of them something like this:

1. 1, 2, 3
2. 1, Y, 3
3. 1, Y, Z
4. 1, 2, Z
5. X, 2, 3
6. X, Y, 3
7. X, Y, Z
8. X, 2, Z

You can solve your problem by generating all the combinations for {0,1} pairs:

000
001
010
011
100
101
110
111

and then map these results to your symbols, using for example this mapping table:
{1,X} --> {0,1}
{2,Y} --> {0,1}
{3,Z} --> {0,1}

to give the answers as here:
000 --> 123
001 --> 12Z
010 --> 1Y3
011 --> 1YZ
100 --> X23
101 --> X2Z
110 --> XY3
111 --> XYZ

arrplayr
February 10th, 2009, 01:17 PM
Peter,
Thank You! Thank You! Thank You!

This was exactly what I wanted!

Arben