Re: Combinatorics question

*To*: mathgroup at smc.vnet.net*Subject*: [mg3309] Re: Combinatorics question*From*: ianc (Ian Collier)*Date*: Sun, 25 Feb 1996 03:20:49 -0500*Organization*: Wolfram Research, Inc.*Sender*: owner-wri-mathgroup at wolfram.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. > Thanks in advance for your help. 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 Skiena (published by Addison Wesley). I hope this helps. --Ian ----------------------------------------------------------- Ian Collier Wolfram Research, Inc. ----------------------------------------------------------- tel:(217) 398-0700 fax:(217) 398-0747 ianc at wolfram.com Wolfram Research Home Page: http://www.wolfram.com/ ----------------------------------------------------------- ==== [MESSAGE SEPARATOR] ====