MathGroup Archive 1996

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Combinations function?


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
> 
> 
> 
> 


  • Prev by Date: Re: Cross product
  • Next by Date: RSA and PowerMod-Function
  • Previous by thread: Combinations function?
  • Next by thread: 3D-Plot of data points