Re: Combinations function?
- To: mathgroup at smc.vnet.net
- Subject: [mg5470] Re: [mg5447] Combinations function?
- From: Robert Pratt <rpratt at math.unc.edu>
- Date: Wed, 11 Dec 1996 03:15:54 -0500
- Sender: owner-wri-mathgroup at wolfram.com
Use the function KSubsets in the Combinatorica standard package.
In[1]:= Needs["DiscreteMath`Combinatorica`"]
In[2]:= ?KSubsets
KSubsets[l,k] returns all subsets of set l containing exactly k elements,
ordered lexicographically.
In[2]:= KSubsets[{a,b,c,d},3]
Out[2]= {{a, b, c}, {a, b, d}, {a, c, d}, {b, c, d}}
Rob Pratt
Department of Mathematics
The University of North Carolina at Chapel Hill
CB# 3250, 331 Phillips Hall
Chapel Hill, NC 27599-3250
rpratt at math.unc.edu
On Sat, 7 Dec 1996, Erik Kulstad wrote:
> There is already a function to obtain the number of permutations possible
> from a set (or list); but does anyone know of a function to obtain the
> combinations?
>
> For example, if the set is {a,b,c,d}, I want to list all 3-member
> combinations possible, yielding {{a,b,c},{a,b,d},{a,c,d},{b,c,d}}.
>
>
> Thanks in advance,
> Erik Kulstad
>
>
>
>