I apologize in advance for the incompleteness of this post. I won't be back at my desk until later today and i will make a more complete post then.

I am working on an algorithm where I need to generate all possible combinations of a series of integers. These are "combinations" as opposed to "permutations" meaning that the order is not important. The set 1,2,3 is the same as the set 3,2,1 or 2,1,3, etc. Most algorithms for this kind of thing are create all the combinations of size k from the set of size n. I am creating all the combinations of all sizes k.

For example, if my set is, 0,1,2,3,4, I find 31 possible combinations.

Mathematically this is something like 5!-redundancies, but I don't remember off hand how to calculate the redundancies so I'm not sure that 31 is correct. It looks correct as far as I can see.Code:0 // 0 by itself 0,1 // pairs on 0 0,2 0,3 0,4 0,1,2 // triplets on 0 0,1,3 0,1,4 0,2,3 0,2,4 0,3,4 0,1,2,3 // quadruplets on 0 0,1,2,4 0,1,3,4 0,2,3,4 0,1,2,3,4 // quintuplets on 0 1 // 1 by itself 1,2 // pairs on 1 1,3 1,4 1,2,3 1,2,4 1,3,4 1,2,3,4 2 2,3 2,4 2,3,4 3 3,4 4

What I have tried is starting with the first element in the set and building each pair on that element, each triplet, etc. it seems as if a simple looping structure should be able to product this, something like

My algorithm keeps getting more and more complicated and it seems like it should be simple. I have some versions that work, but they produce duplicates that need to be removed after the fact. It seems that sorting and creating the sub-sets based on the sorted order should prevent duplicates. My overall algorithm is much more complex in that there are a number of tasks that are being performed along the way (each subset is being evaluated) and the code has become difficult to debug. Some of the actual data I am working with has sets of 40 or so and the output is too large to examine manually (calculate 40 factorial sometime). I need to restart this an make sure that the basic looping structure is sound.Code:for(i=0; i<set.size()-1; i++) { for(j=i+1; j<set.size(); j++) { } }

I am hoping someone can point me to a reference for how to set up a simple block of code to do this part. It is the kind of thing that must be done all of the time, but my searches haven't turned up quite the right example yet.

If anyone has suggestions, they would be very much appreciated. I will post more complete code samples later today when I get back. At the moment, I am actually compiling with gcc3 under 32-bit cygwin and 64-bit opensuse linux.

LMHmedchem