|
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
Syntax public static IEnumerable<int[]> Sequences(
this int[] symbols,
bool inPlace = false
)
<ExtensionAttribute>
Public Shared Function Sequences (
symbols As Integer(),
Optional inPlace As Boolean = false
) As IEnumerable(Of Integer())
Request Example
View SourceParameters
- symbols
- 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:
IEnumerableInt32Usage 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).
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:
foreach (int[] row in Combinatorics.Sequences(new[] { 2, 2 }))
{
}
See Also