Click or drag to resize

Combination Constructor (Int32, Int32)

Initializes a new combination of Rank 0 with the supplied number of picks from the supplied number of choices.

Namespace:  Kaos.Combinatorics
Assembly:  KaosCombinatorics (in KaosCombinatorics.dll) Version: 5.0.0.6
Syntax
C#
public Combination(
	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
ArgumentOutOfRangeException When negative value supplied; when picks greater than choices.
OverflowExceptionWhen the numbers are just too big.
Remarks
Supplying a value for choices that is greater than picks will instantiate a k-combination also known as a pick-combination.
Examples
C#
using System;
using Kaos.Combinatorics;

namespace ExampleApp
{
    class CnExample01
    {
        static void Main()
        {
            var cn = new Combination (choices:6, picks:3);

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

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

        /* Output:

        n=6, k=3:

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

        */
    }
}
See Also