Re: Combinatorics question

• Subject: [mg3309] Re: Combinatorics question
• From: ianc (Ian Collier)
• Date: 25 Feb 1996 14:28:14 -0600
• Approved: usenet@wri.com
• Distribution: local
• Newsgroups: wri.mathgroup
• Organization: Wolfram Research, Inc.
• Sender: daemon at wri.com

```In article <4gi621\$jkv at dragonfly.wolfram.com>, <PESCC at CUNYVM.CUNY.EDU> wrote:

> Can somenone help me find the following:
>
> I have a list of 20 numbers, and I would like to list all the
> combinations of these numbers taken 6 at a time.  The Binomial
> function tells me there are 38760, but I would like to actually
> see all of them.

You can use the KSubsets function which is defined in
DiscreteMath`Combinatorica` one of the standard packages
distributed with Mathematica.

Here is a, slightly smaller, example:

In[1]:=
nums = Range[ 6 ]
Out[1]=
{1, 2, 3, 4, 5, 6}

In[2]:=
Needs[ "DiscreteMath`Combinatorica`" ]

In[3]:=
?KSubsets

KSubsets[l,k] returns all subsets of set l containing exactly
k elements, ordered lexicographically.

In[4]:=
KSubsets[ nums, 2 ]
Out[4]=
{{1, 2}, {1, 3}, {1, 4}, {1, 5}, {1, 6}, {2, 3}, {2, 4},

{2, 5}, {2, 6}, {3, 4}, {3, 5}, {3, 6}, {4, 5}, {4, 6},

{5, 6}}

The Guide to Standrad Mathematica Packages provides brief
documentation of this package. It is documented in detail
in the book "Implementing Discrete Mathematics:
Combinatorics and Graph Theory with Mathematica" by Steven

I hope this helps.

--Ian

-----------------------------------------------------------
Ian Collier
Wolfram Research, Inc.
-----------------------------------------------------------
tel:(217) 398-0700   fax:(217) 398-0747    ianc at wolfram.com
-----------------------------------------------------------

```

• Prev by Date: Re: Combinatorics question
• Next by Date: Re:More Anomalous Behaviour with Indexed Variables
• Previous by thread: Re: Combinatorics question
• Next by thread: Re: Combinatorics question