MathGroup Archive 2005

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

Search the Archive

Re: Combinations


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



  • Prev by Date: Re: Zero argument functions
  • Next by Date: Re: Mathematica and version control systems
  • Previous by thread: Combinations
  • Next by thread: Re: Re: Combinations