diff --git a/class/LogicFunction.php b/class/LogicFunction.php index 9e663b8..c1ae9cf 100644 --- a/class/LogicFunction.php +++ b/class/LogicFunction.php @@ -203,6 +203,9 @@ class LogicFunction implements JsonSerializable public static function isCorrectDNF(array $input_vars, string $exp): bool { $exp = trim($exp); // trim spaces + if ($exp === "0") { + return true; + } $minterms = explode("|", $exp); // break up the expression into minterms $minterms = array_map(fn($mt) => trim($mt, " ()\t"), $minterms); // strip the parentheses off the minterms $minterms = array_map(fn($mt) => str_replace(" ", "", $mt), $minterms); // remove spaces @@ -250,7 +253,12 @@ class LogicFunction implements JsonSerializable $minterms[] = $term; } } - return join(" | ", $minterms); + + $dnf = join(" | ", $minterms); + if ($dnf === "") { + $dnf = "0"; + } + return $dnf; } public function drawNetwork(string $outvar = "f"): string diff --git a/class/Tasks/LogicFunctionTask.php b/class/Tasks/LogicFunctionTask.php index 11fa95f..1be87a8 100644 --- a/class/Tasks/LogicFunctionTask.php +++ b/class/Tasks/LogicFunctionTask.php @@ -15,9 +15,6 @@ class LogicFunctionTask extends LogicTaskBase $this->setCorrectAnswer($this->getLogicFunction()->getExpression()); } else { $dnf = $this->getLogicFunction()->toDNF(); - if ($dnf === "") { - $dnf = "0"; - } $this->setCorrectAnswer($dnf); } }