﻿ Combinatorics.Sequences Method (Int32, Boolean)

Provides a way to enumerate all possible ordered permutations with repetitions allowed (i.e. a truth table), without using many memory allocations.

Namespace:  Accord.Math
Assembly:  Accord.Math (in Accord.Math.dll) Version: 3.8.0
Syntax
public static IEnumerable<int[]> Sequences(
int length,
bool inPlace = false
)

#### Parameters

length
Type: SystemInt32
The length of the sequence to generate.
inPlace (Optional)
Type: SystemBoolean
If set to true, the different generated sequences will be stored in the same array, thus preserving memory. However, this may prevent the samples from being stored in other locations without having to clone them. If set to false, a new memory block will be allocated for each new object in the sequence.

#### Return Value

Type: IEnumerableInt32
Examples

Suppose we would like to generate the same sequences shown in the TruthTable(Int32, Int32)example, however, without explicitly storing all possible combinations in an array. In order to iterate over all possible combinations efficiently, we can use:

int length = 3;  // The number of variables; or number
// of columns in the generated table.

foreach (int[] row in Combinatorics.Sequences(length))
{
// The following sequences will be generated in order:
//
//   new int[] { 0, 0, 0 },
//   new int[] { 0, 0, 1 },
//   new int[] { 0, 1, 0 },
//   new int[] { 0, 1, 1 },
//   new int[] { 1, 0, 0 },
//   new int[] { 1, 0, 1 },
//   new int[] { 1, 1, 0 },
//   new int[] { 1, 1, 1 },
}