From c1351d5ec0317e4c90e0fe022f866d11ae973273 Mon Sep 17 00:00:00 2001 From: Zander Thannhauser Date: Wed, 11 Jun 2025 08:46:59 -0500 Subject: [PATCH] . --- main.c | 51 +++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 37 insertions(+), 14 deletions(-) diff --git a/main.c b/main.c index 22aca34..d10f440 100644 --- a/main.c +++ b/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,22 +1148,43 @@ int main(int argc, char* const* argv) printf("%2i: ", costs[truthtable]), print(truthtable), puts(""); } } - else for (char* line; (line = readline(">>> ")); free(line)) + else { - uint16_t truthtable = evaluate(line); - - // printf("truthtable = 0b%016b\n", truthtable); - - if (costs[truthtable] == INT_MAX) + int max_cost = 0; + + for (int i = 0; i < N; i++) { - puts("unreachable"); + int cost = costs[i]; + + if (cost != INT_MAX && max_cost < cost) + { + max_cost = cost; + } } - else + + // 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)) { - printf("%2i: ", costs[truthtable]), print(truthtable), puts(""); + uint16_t truthtable = evaluate(line); + + // printf("truthtable = 0b%016b\n", truthtable); + + if (costs[truthtable] == INT_MAX) + { + puts("unreachable"); + } + else + { + printf("%2i: ", costs[truthtable]), print(truthtable), puts(""); + } } } - + return 0; }