Click or drag to resize
Accord.NET (logo)

CombinatoricsTruthTable Method (Int32)

Generates all possible two symbol ordered permutations with repetitions allowed (a truth table).

Namespace:  Accord.Math
Assembly:  Accord.Math (in Accord.Math.dll) Version: 3.8.0
Syntax
public static int[][] TruthTable(
	int length
)
Request Example View Source

Parameters

length
Type: SystemInt32
The length of the sequence to generate.

Return Value

Type: Int32
Examples

Suppose we would like to generate a truth table for a binary problem. In this case, we are only interested in two symbols: 0 and 1. Let's then generate the table for three binary values

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

// Generate the table using Combinatorics.TruthTable(3)
int[][] table = Combinatorics.TruthTable(length);

// The generated table will be:
{
    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