Click or drag to resize

Permutation Constructor (Int32, Int32, Int64)

Initializes a new permutation 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 Permutation(
	int choices,
	int picks,
	long rank
)

Parameters

choices
Type: SystemInt32
Number of values to choose from.
picks
Type: SystemInt32
Number of elements in the sequence.
rank
Type: SystemInt64
Row index in the ordered Permutation table.
Exceptions
ExceptionCondition
ArgumentOutOfRangeException When picks less than 0 or greater than choices; when choices greater than 20.
Remarks

Supplying a value for choices that is greater than picks will instantiate a k-permutation also known as a variation.

If 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
This is an example of a k-permutation.
C#
using System;
using System.Linq;
using Kaos.Combinatorics;

namespace ExampleApp
{
    class PnExample05
    {
        static void Main()
        {
            // Create a k-permutation:
            var pn = new Permutation (choices:8, picks:4, rank:601);
            Console.WriteLine ($"n={pn.Choices}, k={pn.Picks}, rank={pn.Rank}:\n");

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

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

        /* Output:

        n=8, k=4, rank=601:

        CHAD

        Element at 0 is 2
        Element at 1 is 7
        Element at 2 is 0
        Element at 3 is 3

        */
    }
}
See Also