Click or drag to resize

Multicombination Constructor (Int32, Int32)

Initializes a new multicombination of Rank 0 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
)

Parameters

choices
Type: SystemInt32
Number of values to pick from.
picks
Type: SystemInt32
Number of elements in the sequence.
Exceptions
ExceptionCondition
ArgumentOutOfRangeExceptionWhen negative value supplied; when choices is 0 and picks is not 0.
OverflowExceptionWhen the numbers are just too big.
Remarks
Supplying a value for choices that is greater than picks will instantiate a k-multicombination also known as a k-combination with repetition.
Examples
C#
using System;
using Kaos.Combinatorics;

namespace ExampleApp
{
    class McExample01
    {
        static void Main()
        {
            var mc = new Multicombination (choices:4, picks:3);

            Console.WriteLine ($"n={mc.Choices}, k={mc.Picks}:\n");

            foreach (var row in mc.GetRows())
                Console.WriteLine ($"{row.Rank,2}:  {row}");
        }

        /* Output:

        n=4, k=3:

         0:  { 0, 0, 0 }
         1:  { 0, 0, 1 }
         2:  { 0, 0, 2 }
         3:  { 0, 0, 3 }
         4:  { 0, 1, 1 }
         5:  { 0, 1, 2 }
         6:  { 0, 1, 3 }
         7:  { 0, 2, 2 }
         8:  { 0, 2, 3 }
         9:  { 0, 3, 3 }
        10:  { 1, 1, 1 }
        11:  { 1, 1, 2 }
        12:  { 1, 1, 3 }
        13:  { 1, 2, 2 }
        14:  { 1, 2, 3 }
        15:  { 1, 3, 3 }
        16:  { 2, 2, 2 }
        17:  { 2, 2, 3 }
        18:  { 2, 3, 3 }
        19:  { 3, 3, 3 }

        */
    }
}
See Also