Table of Contents

Class Combinatorial

Namespace
Gamelogic.Extensions.Algorithms
Assembly
Assembly-CSharp.dll

Combinatorial algorithms, including generating tuples, combinations, permutations and partitions.

Except for PowerSet, all methods are implemented after Knuth, described in The Art of Computer Programming Volume 4.

[Version(1, 4, 0)]
public static class Combinatorial
Inheritance
Combinatorial
Inherited Members

Methods

Combinations<T>(IEnumerable<T>, int)

Generates all combinations of m elements selected from the list.

public static IEnumerable<T[]> Combinations<T>(this IEnumerable<T> list, int m)

Parameters

list IEnumerable<T>

The list to select from.

m int

The number of elements in each combination.

Returns

IEnumerable<T[]>

IEnumerable<T[]>.

Type Parameters

T

The type of elements in the list.

Exceptions

ArgumentOutOfRangeException

m;must be nonnegative or m;must be smaller than n

Combinations<T>(int, int, Func<int[], T>)

public static IEnumerable<T> Combinations<T>(int m, int n, Func<int[], T> select)

Parameters

m int
n int
select Func<int[], T>

Returns

IEnumerable<T>

Type Parameters

T

MultiRadixTuples(int[])

Generates all tuples with mixed radixes.

public static IEnumerable<int[]> MultiRadixTuples(int[] radixes)

Parameters

radixes int[]

The array of radixes for each position in the tuple.

Returns

IEnumerable<int[]>

MultiRadixTuples<T>(IEnumerable<IEnumerable<T>>)

public static IEnumerable<T[]> MultiRadixTuples<T>(this IEnumerable<IEnumerable<T>> elements)

Parameters

elements IEnumerable<IEnumerable<T>>

Returns

IEnumerable<T[]>

Type Parameters

T

Partitions<T>(IEnumerable<T>)

Returns a list of all the partitions of a list.

public static IEnumerable<IEnumerable<IEnumerable<T>>> Partitions<T>(this IEnumerable<T> list)

Parameters

list IEnumerable<T>

The list.

Returns

IEnumerable<IEnumerable<IEnumerable<T>>>

IEnumerable<IEnumerable<IEnumerable<T>>>.

Type Parameters

T

Remarks

If the list is (a b c), then ((a) (b c)) and ((a) (b) (c)) would be examples of partitions.

Permutations(int)

Generates all permutations of the numbers 0 to n - 1.

public static IEnumerable<int[]> Permutations(int n)

Parameters

n int

Returns

IEnumerable<int[]>

Permutations<T>(IEnumerable<T>)

Generates all permutations of the list of elements.

public static IEnumerable<T[]> Permutations<T>(this IEnumerable<T> list)

Parameters

list IEnumerable<T>

Returns

IEnumerable<T[]>

Type Parameters

T

PowerSet<T>(IEnumerable<T>)

Returns the power set of the input, that is, the set of all subsets of the input.

public static IEnumerable<IEnumerable<T>> PowerSet<T>(this IEnumerable<T> input)

Parameters

input IEnumerable<T>

The input.

Returns

IEnumerable<IEnumerable<T>>

IEnumerable<IEnumerable<T>>.

Type Parameters

T

Tuples(int)

Generate all possible tuples of length n with digits 0 to n-1.

public static IEnumerable<int[]> Tuples(int n)

Parameters

n int

The length of tuples to generate. All digits are also between 0 and n-1.

Returns

IEnumerable<int[]>

Tuples<T>(IEnumerable<T>)

public static IEnumerable<T[]> Tuples<T>(this IEnumerable<T> list)

Parameters

list IEnumerable<T>

Returns

IEnumerable<T[]>

Type Parameters

T

Tuples<T>(int, Func<int[], T>)

Generates n-tuples of integers 0 to n-1 and applies the selector to them.

public static IEnumerable<T> Tuples<T>(int n, Func<int[], T> select)

Parameters

n int
select Func<int[], T>

Returns

IEnumerable<T>

Type Parameters

T

Exceptions

ArgumentOutOfRangeException

n;must be non negative