Click or drag to resize

Multicombination Constructor (Int32, Int32, Int64)

Initializes a new multicombination of the supplied rank with the supplied number of picks from the supplied number of choices.

Namespace:  Kaos.Combinatorics
Assembly:  KaosCombinatorics (in KaosCombinatorics.dll) Version: 6.0.0.0
Syntax
C#
public Multicombination(
	int choices,
	int picks,
	long rank
)

Parameters

choices
Type: SystemInt32
Number of values to pick from.
picks
Type: SystemInt32
Number of elements in the sequence.
rank
Type: SystemInt64
Row index in the ordered Multicombination table.
Exceptions
ExceptionCondition
ArgumentOutOfRangeExceptionWhen negative value supplied; when choices is 0 and picks is not 0.
OverflowExceptionWhen too many choices.
Remarks

Supplying a value for choices that is greater than picks will instantiate a k-multicombination also known as a k-combination with repetition.

If the supplied rank is out of the range (0..RowCount-1), it will be normalized to the valid range. For example, a value of -1 will produce the last row in the ordered table.

Examples
C#
using System;
using System.Linq;
using Kaos.Combinatorics;

namespace ExampleApp
{
    class McExample05
    {
        static void Main()
        {
            // Create a k-multicombination:
            var mc = new Multicombination (choices:9, picks:7, rank:5973);
            Console.WriteLine ($"n={mc.Choices}, k={mc.Picks}, rank={mc.Rank}:\n");

            // Access elements using the default enumerator:
            var text = String.Concat (mc.Select (ei => (char) ('A' + ei)));
            Console.WriteLine ($"{text}\n");

            // Access elements using the indexer:
            for (int i = 0; i < mc.Picks; ++i)
                Console.WriteLine ($"Element at {i} is {mc[i]}");
        }

        /* Output:

        n=9, k=7, rank=5973:

        DEFFFHI

        Element at 0 is 3
        Element at 1 is 4
        Element at 2 is 5
        Element at 3 is 5
        Element at 4 is 5
        Element at 5 is 7
        Element at 6 is 8

        */
    }
}
See Also