Re: Re: Combinations

*To*: mathgroup at smc.vnet.net*Subject*: [mg61767] Re: [mg61716] Re: [mg61677] Combinations*From*: "Carl K. Woll" <carlw at wolfram.com>*Date*: Sat, 29 Oct 2005 01:32:35 -0400 (EDT)*References*: <200510260501.BAA18717@smc.vnet.net> <200510270901.FAA19404@smc.vnet.net>*Sender*: owner-wri-mathgroup at wolfram.com

Sseziwa Mukasa wrote: > On Oct 26, 2005, at 1:01 AM, xxxxyz at abv.bg wrote: > > >>Hi, >> >>Is there any way to generate combinations per turn in a cycle? I mean >>first generate one combination, do something, generate next, do the >>same thing ... >> >>Thanks. > > > The combinations are called KSubsets in Mathematica, the > Combinatorica package contains the necessary routines. The first > KSubset in lexicographic order is simply Range[k], you can use > NextKSubset to see the others for example: > > <<DiscreteMath`Combinatorica` > Block[{subset = Range[3]},Prepend[Table[subset = NextKSubset[Range > [5], subset], {4}], Range[3]]] > > will return the first 5 subsets of length 3 of {1,2,3,4,5} in > lexicographic order. There are functions to get the KSubsets in > other orders in Combinatorica, I suggest you read the Help Browser > information or read "Computational Discrete Mathematics: > Combinatorics and Graph Theory with Mathematica" by Steven Skiena and > Sriram Pemmaraju for more information on the package. > > Regards, > > Ssezi > Starting in version 5.1, the function Subsets will also do the above: In[3]:= Subsets[{1,2,3,4,5},{3},5] Out[3]= {{1,2,3},{1,2,4},{1,2,5},{1,3,4},{1,3,5}} If we are interested in the 9th subset of {1,2,3,4,5} of length 3: In[4]:= Subsets[{1,2,3,4,5},{3},{9}] Out[4]= {{2,4,5}} Carl Woll Wolfram Research

**References**:**Combinations***From:*"xxxxyz@abv.bg" <xxxxyz@abv.bg>

**Re: Combinations***From:*Sseziwa Mukasa <mukasa@jeol.com>