Added a way to print out instead of stdout but to a file (everything about the process but errors (those still go to stderr) and made it so now someone can actually use echo -e "" | ./bin/stergios (prior this was impossible to do due to readline quirks)
Stergios Upload Compile Checker / Explore-Gitea-Actions (push) Successful in 7s

This commit is contained in:
metallaxis committed 2026-07-05 05:31:32 +03:00
1 parent 030b73597f
commit 49467332de
10 files changed
+191 -63

No files matched your search

+23 -16
View File
@@ -52,12 +52,12 @@ void try_push_children(Node* curr) {
}
}
static bool bfs(int128_t* sum, int128_t a0, int128_t b0, int128_t c0, int print_mode) {
static bool bfs(int128_t* sum, int128_t a0, int128_t b0, int128_t c0, int print_mode, FILE* output) {
node_pool_reset();
queue_clear();
clear_hash_table();
Node* root = node_pool_alloc();
Node* root = node_pool_next();
if (!root) return false;
root->a = a0; root->b = b0; root->c = c0;
@@ -100,21 +100,28 @@ static bool bfs(int128_t* sum, int128_t a0, int128_t b0, int128_t c0, int print_
p = p->parent;
}
printf("\nSolution found!\n");
printf("Initial: (");
print_int128(a0); printf(", ");
print_int128(b0); printf(", ");
print_int128(c0); printf(")\n");
if (output) {
fprintf(output, "\nSolution found!\n");
fprintf(output, "Initial: (");
fprint_int128(output, a0); fprintf(output, ", ");
fprint_int128(output, b0); fprintf(output, ", ");
fprint_int128(output, c0); fprintf(output, ")\n");
printf("Final: (");
print_int128(found->a); printf(", ");
print_int128(found->b); printf(", ");
print_int128(found->c); printf(")\n");
fprintf(output, "Final: (");
fprint_int128(output, found->a); fprintf(output, ", ");
fprint_int128(output, found->b); fprintf(output, ", ");
fprint_int128(output, found->c); fprintf(output, ")\n");
printf("Moves (%i): %s\n", max_moves, moves);
fprintf(output, "Moves (%i): %s\n", max_moves, moves);
}
} else if (print_mode == 2) {
print_int128(c0);
printf(" the required amount of moves is: %i\n", max_moves);
if (output) {
fprintf(output, "For (");
fprint_int128(output, a0); fprintf(output, ", ");
fprint_int128(output, b0); fprintf(output, ", ");
fprint_int128(output, c0);
fprintf(output, ") the required amount of moves is: %i\n", max_moves);
}
}
*sum += max_moves;
@@ -125,7 +132,7 @@ static bool bfs(int128_t* sum, int128_t a0, int128_t b0, int128_t c0, int print_
return true;
}
bool solve(int128_t* sum, int128_t a0, int128_t b0, int128_t c0, int print_mode) {
bool solve(int128_t* sum, int128_t a0, int128_t b0, int128_t c0, int print_mode, FILE* output) {
/* Fallback to BFS */
return bfs(sum, a0, b0, c0, print_mode);
return bfs(sum, a0, b0, c0, print_mode, output);
}