This commit is contained in:
Wiesner András 2025-10-14 16:23:37 +02:00
parent 495c6447d0
commit f6f422abcd
2 changed files with 9 additions and 4 deletions

View File

@ -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

View File

@ -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);
}
}