MathGroup Archive 1997

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

Search the Archive

Re: List manipulation

  • To: mathgroup at smc.vnet.net
  • Subject: [mg7433] Re: [mg7390] List manipulation
  • From: Robert Pratt <rpratt at math.unc.edu>
  • Date: Sat, 31 May 1997 15:08:31 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

You mean that there will be 8-choose-4 = 70 elements.

Try 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[Range[8],4]

Out[2]= {{1, 2, 3, 4}, {1, 2, 3, 5}, {1, 2, 3, 6}, {1, 2, 3, 7},

>    {1, 2, 3, 8}, {1, 2, 4, 5}, {1, 2, 4, 6}, {1, 2, 4, 7}, {1, 2, 4, 8},

>    {1, 2, 5, 6}, {1, 2, 5, 7}, {1, 2, 5, 8}, {1, 2, 6, 7}, {1, 2, 6, 8},

>    {1, 2, 7, 8}, {1, 3, 4, 5}, {1, 3, 4, 6}, {1, 3, 4, 7}, {1, 3, 4, 8},

>    {1, 3, 5, 6}, {1, 3, 5, 7}, {1, 3, 5, 8}, {1, 3, 6, 7}, {1, 3, 6, 8},

>    {1, 3, 7, 8}, {1, 4, 5, 6}, {1, 4, 5, 7}, {1, 4, 5, 8}, {1, 4, 6, 7},

>    {1, 4, 6, 8}, {1, 4, 7, 8}, {1, 5, 6, 7}, {1, 5, 6, 8}, {1, 5, 7, 8},

>    {1, 6, 7, 8}, {2, 3, 4, 5}, {2, 3, 4, 6}, {2, 3, 4, 7}, {2, 3, 4, 8},

>    {2, 3, 5, 6}, {2, 3, 5, 7}, {2, 3, 5, 8}, {2, 3, 6, 7}, {2, 3, 6, 8},

>    {2, 3, 7, 8}, {2, 4, 5, 6}, {2, 4, 5, 7}, {2, 4, 5, 8}, {2, 4, 6, 7},

>    {2, 4, 6, 8}, {2, 4, 7, 8}, {2, 5, 6, 7}, {2, 5, 6, 8}, {2, 5, 7, 8},

>    {2, 6, 7, 8}, {3, 4, 5, 6}, {3, 4, 5, 7}, {3, 4, 5, 8}, {3, 4, 6, 7},

>    {3, 4, 6, 8}, {3, 4, 7, 8}, {3, 5, 6, 7}, {3, 5, 6, 8}, {3, 5, 7, 8},

>    {3, 6, 7, 8}, {4, 5, 6, 7}, {4, 5, 6, 8}, {4, 5, 7, 8}, {4, 6, 7, 8},

>    {5, 6, 7, 8}}

In[3]:= Length[%]

Out[3]= 70

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

http://www.math.unc.edu/Grads/rpratt/

On Fri, 30 May 1997, V. Nandagopal wrote:

> Hello,
> 
> 	I have a list X={1,2,3,4,5,6,7,8}. How do I get a list of the
> folllowing kind:
> 
> 	S={{1,2,3,4}, {1,2,3,5}, {1,2,3,6}, .....}. 
> 
> S will have 8-choose-2 = 70 elements. Each element of S should have length
> 4.
> 
> 	Is there any function which does such list making? Something of
> the form 
> 
> 	?????[list, n]
> 
> 	Thanks in advance.
> 
> 
> 	V. Nandagopal
> 	School of Mathematics
> 	Tata Institute of Fundamental Research
> 	Colaba, Bombay 400 005, India
> 
> 	e-mail: nandgopa at math.tifr.res.in
> 
> 
> 
> 



  • Prev by Date: Re: Version 3.0 Speed
  • Next by Date: Re: Is there a better way to do a 3D List Plot?
  • Previous by thread: Re: List manipulation
  • Next by thread: About PolynomialDivision & the Notebook Frontend