public static KMapLoop SeedLoop(int startIndex) { // Create a size-1 loop containing the index (which should represent an enabled truth-table bit). KMapLoop loop = new KMapLoop(); foreach (bool bit in BinaryHelper.BinaryValueToBoolean(startIndex, Main.Instance.inputLength)) { loop.Add(new List <bool>() { bit }); } return(loop); }
public void GenerateTruthTable(string expression) { int variableCount = VariableExpression.VariableCount(expression); Debug.Log("Generated an expression with " + variableCount.ToString() + " variables."); if (variableCount == 0) { bool outcome = VariableExpression.GenerateTruthValue(expression, new bool[0]); TableEntry displayResult = CreateTableEntry(0); displayResult.OverrideVariableLabels("Result (identity): ", outcome); displayResult.PositionInTable(0); } else { if (variableCount >= 2) { Main.Instance.UpdateInputLength(variableCount); } labelVariableNames.text = "Table for " + variableCount + " variable(s) " + VariableExpression.logicVariableAlphabet.Substring(0, variableCount); int bitsSet = 0; // Iterate through each row / combination of the binary truth table. for (int i = 0; i < BinaryHelper.PowBaseTwo(variableCount); i++) { bool[] variableBits = BinaryHelper.BinaryValueToBoolean(i, variableCount); bool outcome = VariableExpression.GenerateTruthValue(expression, variableBits); TableEntry tableEntry = CreateTableEntry(i / itemsPerColumn); tableEntry.SetVariableLabels(variableBits, outcome); tableEntry.PositionInTable(i % itemsPerColumn); if (outcome) { bitsSet++; } if (variableCount >= 2) { Main.Instance.gridState[i] = outcome; } } outputDetail.text = $"{bitsSet} / {BinaryHelper.PowBaseTwo(variableCount)} truthy bits"; } }
public void UpdateTruthTable() { labelVariableNames.text = "Table for " + Main.Instance.inputLength + " variable(s) " + VariableExpression.logicVariableAlphabet.Substring(0, Main.Instance.inputLength); // Make a truth table to represent the current grid state. for (int i = 0; i < Main.Instance.GridSize; i++) { bool[] variableBits = BinaryHelper.BinaryValueToBoolean(i, Main.Instance.inputLength); bool outcome = Main.Instance.gridState[i]; TableEntry tableEntry = CreateTableEntry(i / itemsPerColumn); tableEntry.SetVariableLabels(variableBits, outcome); tableEntry.PositionInTable(i % itemsPerColumn); } int bitsSet = BinaryHelper.CountBitsSet(Main.Instance.gridState); outputDetail.text = $"{bitsSet} / {Main.Instance.GridSize} truthy bits"; }