pseudosig has asked for the wisdom of the Perl Monks concerning the following question:

I've searched through this site trying to find code to generate all combination arrays (of length n) from some other array (call it the pool array) that the combination arrays are picking from. I've found many that give all combinations equal to the size of the array (i.e. (pool array size)! many of them... that's the factorial of the pool array size)). But this isn't what im looking for. Rather, I want to generate a list of combination arrays of length smaller or equal to that of the pool array. Basically, list the actual combination arrays that yield in number nCr (for you math people) I'd would love any code for this, since i for some reason can't come up with an effective and correct alg. Thanks, Pseudosig

Replies are listed 'Best First'.
Re: Combinations... again
by blokhead (Monsignor) on Jul 20, 2005 at 22:19 UTC
    Here is some code I wrote that uses an iterator so the entire set of combinations does not all need to be in memory at once: Iterating over combinations

    blokhead

      That's exactly what i need. Thank you much!
Re: Combinations... again
by ishnid (Monk) on Jul 20, 2005 at 23:06 UTC
Re: Combinations... again
by tlm (Prior) on Jul 20, 2005 at 22:19 UTC

    What's wrong with simply pooling the combinations for 1..n?

    the lowliest monk

Re: Combinations... again
by Solo (Deacon) on Jul 21, 2005 at 00:57 UTC
    You can find discussion of some different approaches to combinatorial problems here. IIRC, Algorithm::Loops has an example similar to what you're looking for. The example I was thinking of is not in the POD, which was using the OnlyWhen parameter with NestedLoops to only return combinations that satisfied a condition--it's in tye's post in the above thread.

    --Solo

    --
    You said you wanted to be around when I made a mistake; well, this could be it, sweetheart.