.
This commit is contained in:
parent
a320cdba33
commit
c1351d5ec0
1 changed files with 37 additions and 14 deletions
33
main.c
33
main.c
|
|
@ -104,6 +104,8 @@ static void parse_args(int argc, char* const* argv)
|
|||
use_operators.xor = true;
|
||||
else if (!strcmp(moving, "nxor"))
|
||||
use_operators.nxor = true;
|
||||
else if (!strcmp(moving, "ternary"))
|
||||
use_operators.ternary = true;
|
||||
else
|
||||
{
|
||||
assert(!"TODO");
|
||||
|
|
@ -342,10 +344,10 @@ void calculate_simplifications(void)
|
|||
costs[truthtable] = cost;
|
||||
}
|
||||
|
||||
append(W, 1), lookup[W].kind = ek_W;
|
||||
append(X, 1), lookup[X].kind = ek_X;
|
||||
append(Y, 1), lookup[Y].kind = ek_Y;
|
||||
append(Z, 1), lookup[Z].kind = ek_Z;
|
||||
append(W, 0), lookup[W].kind = ek_W;
|
||||
append(X, 0), lookup[X].kind = ek_X;
|
||||
append(Y, 0), lookup[Y].kind = ek_Y;
|
||||
append(Z, 0), lookup[Z].kind = ek_Z;
|
||||
|
||||
append(0, 1), lookup[0].kind = ek_0;
|
||||
append(M, 1), lookup[M].kind = ek_1;
|
||||
|
|
@ -1146,7 +1148,27 @@ int main(int argc, char* const* argv)
|
|||
printf("%2i: ", costs[truthtable]), print(truthtable), puts("");
|
||||
}
|
||||
}
|
||||
else for (char* line; (line = readline(">>> ")); free(line))
|
||||
else
|
||||
{
|
||||
int max_cost = 0;
|
||||
|
||||
for (int i = 0; i < N; i++)
|
||||
{
|
||||
int cost = costs[i];
|
||||
|
||||
if (cost != INT_MAX && max_cost < cost)
|
||||
{
|
||||
max_cost = cost;
|
||||
}
|
||||
}
|
||||
|
||||
// we subtract 4 from the cost because
|
||||
puts("");
|
||||
printf("I can simplify any tree down to %i operators or less.\n",
|
||||
max_cost);
|
||||
puts("");
|
||||
|
||||
for (char* line; (line = readline(">>> ")); free(line))
|
||||
{
|
||||
uint16_t truthtable = evaluate(line);
|
||||
|
||||
|
|
@ -1161,6 +1183,7 @@ int main(int argc, char* const* argv)
|
|||
printf("%2i: ", costs[truthtable]), print(truthtable), puts("");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue