Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2005

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

Search the Archive

Re: Re: Combinations

Sseziwa Mukasa wrote:
> On Oct 26, 2005, at 1:01 AM, xxxxyz at wrote:
>>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 ...
> 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:



If we are interested in the 9th subset of {1,2,3,4,5} of length 3:



Carl Woll
Wolfram Research

  • Prev by Date: New LinkageDesigner application for mechanical design with Mathematica
  • Next by Date: Re: A Problem with the NonlinearFit?
  • Previous by thread: Re: Combinations
  • Next by thread: multidimensional interpolation