Click or drag to resize

Multicombination Constructor (Int32, Int32)

Initializes a new multicombination from elements supplied in source picked from the supplied number of choices.

Namespace:  Kaos.Combinatorics
Assembly:  KaosCombinatorics (in KaosCombinatorics.dll) Version: 5.0.0.6
Syntax
C#
public Multicombination(
	int choices,
	int[] source
)

Parameters

choices
Type: SystemInt32
Number of values to pick from.
source
Type: SystemInt32
Array of integers.
Exceptions
ExceptionCondition
ArgumentNullExceptionWhen source is null.
ArgumentOutOfRangeException When source contains invalid data; when choices is 0 and source is not empty.
Remarks
Supplying a value for choices that is greater than the number of elements in source will instantiate a k-multicombination also known as a k-combination with repetition.
Examples
C#
using System;
using Kaos.Combinatorics;

namespace ExampleApp
{
    class McExample04
    {
        static void Main()
        {
            // Create a k-multicombination of the supplied rank:
            var mc = new Multicombination (choices:6, picks:4, rank:25);
            Console.WriteLine ($"{mc}  n={mc.Choices}, k={mc.Picks}, rank={mc.Rank}\n");

            // Assign -1 to get the last rank:
            mc.Rank = -1;
            Console.WriteLine ($"{mc}  n={mc.Choices}, k={mc.Picks}, last={mc.Rank}\n");

            // Rank will always stay in bounds:
            mc.Rank = mc.Rank + 1;
            Console.WriteLine ($"{mc}  n={mc.Choices}, k={mc.Picks}, rank={mc.Rank}\n");

            // Create a k-multicombination of n=9 from the supplied picks:
            mc = new Multicombination (9, new int[] { 1, 1, 3, 8 });
            Console.WriteLine ($"{mc}  n={mc.Choices}, k={mc.Picks}, rank={mc.Rank}");
        }

        /* Output:

        { 0, 1, 1, 5 }  n=6, k=4, rank=25

        { 5, 5, 5, 5 }  n=6, k=4, last=125

        { 0, 0, 0, 0 }  n=6, k=4, rank=0

        { 1, 1, 3, 8 }  n=9, k=4, rank=185

        */
    }
}
See Also