in reply to Re: Permutation seed generator
in thread Permutation seed generator

Geez, the pixels were still warm on my post before you blasted my hilarious code with that 8 liner! Oh woe is me. Days of labor only to see that. ha ha!

My only question then is how can you set the limit on the length of subsets that get returned. I mean if I only want to see every subset with 2 or more digits? I'm not very familiar with bitshifting and that exponentiation ** thing is throwing me too.

Oh well. More reading....

Thanks!

Replies are listed 'Best First'.
Re: Re: Re: Permutation seed generator
by kvale (Monsignor) on May 06, 2004 at 06:33 UTC
    Probably the easiest way to get subsets of a particular size is simply to add a conditional to the print statement:
    print join " ", @subset, "\n" if @subset == 3;
    A little bit more explanation: The number of subsets of a set is 2**$n, with $n the number of elements in the set. So each integer from 0 to 2**n-1 is associated with a unique subset. To get the subset, I associate each bit position with an element of the set. That bit set to 1 means the element is in the subset, 0 means it isn't. The bitshifting and mod operation are used to extract the bit at position $pos to test for membership of that element in the subset.

    -Mark