Permutations algoritm?

sismex01 at hebmex.com sismex01 at hebmex.com
Fri Nov 15 17:59:12 EST 2002


> From: Ron Levine [mailto:ron at dorianresearch.com]
> Sent: Friday, November 15, 2002 4:57 PM
> 
> On Fri, 15 Nov 2002 15:51:04 -0600, sismex01 at hebmex.com wrote:
> 
> >> From: William Park [mailto:opengeometry at yahoo.ca]
> >> Sent: Friday, November 15, 2002 3:42 PM
> >> 
> >> sismex01 at hebmex.com wrote:
> >> > Does anybody have a clear, simple, permutations algorithm
> >> > in Python?
> >> 
> >> Would you care to explain this?  Permutation can mean 
> >> different things.
> >> Concrete example might be good...
> >>
> >
> >Of a set of different items 'S', obtain all distinct subsets of 'n'
> >items where all items in the subset are different.
> >
> >So, if I have, for example:
> >
> >   S = [ 0, 1, 2, 3 ]
> >
> >the universe of available subsets of 3 items would be:
> >
> >   s = [ (0, 1, 2),
> >         (0, 1, 3),
> >         (0, 2, 3),
> >         (1, 2, 3) ]
> >
> >the universe of available subsets of 2 items would be:
> >
> >   s = [ (0, 1),
> >         (0, 2),
> >         (0, 3),
> >         (1, 2),
> >         (1, 3),
> >         (2, 3) ]
> >
> >Any help?
> >
> 
> This is not the conventional meaning of "permutation" in the
> mainstream mathematical lexicon.    Rather, the term applies to a set
> of distinct objects and means the set of all possible different ways
> of ordering them.  The number of permutations of a set of n things is
> n! (factorial).
> 
> What you describe are combinations and power set.  
> 
> Combinations refers to the number of different ways of selecting k
> things out of a set of n things, without regard to ordering, i.e. the
> number of different k-element subsets of an n-element set.  The number
> of such combinations is the binomial coefficient 
> C(n,k) = n!/(k!(n-k!) )
> 
> The power set is the set of all distinct subsets of a set.  Its size
> is the sum of C(n,k), k ranges from 0 to n which happens to equal 2^n.
>

Yes, you are very correct; I'm doing it by hand (paper a pencil), and
it just hit me that I'm looking for combinations and not permutations,
because I don't care about the order.

:-)

-gustavo




More information about the Python-list mailing list