Click or drag to resize
Accord.NET (logo)

CombinatoricsSequences 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
public static IEnumerable<int[]> Sequences(
	this int[] symbols,
	bool inPlace = false
Request Example View Source


Type: SystemInt32
The number of symbols for each variable.
inPlace (Optional)
Type: SystemBoolean
If set to true, the different generated permutations 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

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type . When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).

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:

foreach (int[] row in Combinatorics.Sequences(new[] { 2, 2 }))
    // 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 },
See Also