       Re: Re: Combinations

```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},Prepend[Table[subset = NextKSubset[Range
> , subset], {4}], Range]]
>
> 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
>
> Regards,
>
> Ssezi
>

Starting in version 5.1, the function Subsets will also do the above:

In:=
Subsets[{1,2,3,4,5},{3},5]

Out=
{{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:=
Subsets[{1,2,3,4,5},{3},{9}]

Out=
{{2,4,5}}

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