| Combination Constructor (Int32, Int32) |
Initializes a new combination 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 public Combination(
int choices,
int[] source
)
Parameters
- choices
- Type: SystemInt32
Number of values to pick from. - source
- Type: SystemInt32
Array of integers.
Exceptions Remarks
Supplying a value for choices that is greater than the number of elements in source
will instantiate a k-combination also known as a pick-combination.
Examples using System;
using Kaos.Combinatorics;
namespace ExampleApp
{
class CnExample04
{
static void Main()
{
var cn = new Combination (choices:6, picks:4, rank:2);
Console.WriteLine ($"{cn} n={cn.Choices}, k={cn.Picks}, rank={cn.Rank}\n");
cn.Rank = -1;
Console.WriteLine ($"{cn} n={cn.Choices}, k={cn.Picks}, last={cn.Rank}\n");
cn.Rank = cn.Rank + 1;
Console.WriteLine ($"{cn} n={cn.Choices}, k={cn.Picks}, rank={cn.Rank}\n");
cn = new Combination (9, new int[] { 2, 4, 6, 8 });
Console.WriteLine ($"{cn} n={cn.Choices}, k={cn.Picks}, rank={cn.Rank}");
}
}
}
See Also