Created an additional printing method.
Stergios Upload Compile Checker / Explore-Gitea-Actions (push) Successful in 3s

This commit is contained in:
metallaxis committed 2026-07-05 05:59:57 +03:00
1 parent 49467332de
commit fa7aa240e1
4 files changed
+27 -9

No files matched your search

+3 -1
View File
@@ -13,6 +13,7 @@ void try_push_children(Node* curr);
/** /**
* @brief Runs a solver to find the minimum moves to reach a triplet with zero * @brief Runs a solver to find the minimum moves to reach a triplet with zero
* @param sum Pointer to store the sum of moves for the found solution * @param sum Pointer to store the sum of moves for the found solution
* @param gcd The GCD of the initial triplet
* @param a0 The initial value of a * @param a0 The initial value of a
* @param b0 The initial value of b * @param b0 The initial value of b
* @param c0 The initial value of c * @param c0 The initial value of c
@@ -20,6 +21,7 @@ void try_push_children(Node* curr);
* @param output The file pointer for output (can be NULL) * @param output The file pointer for output (can be NULL)
* @return 1 if a solution is found, 0 otherwise * @return 1 if a solution is found, 0 otherwise
*/ */
bool solve(int128_t* sum, int128_t a0, int128_t b0, int128_t c0, int print_mode, FILE* output); bool solve(int128_t* sum, int128_t gcd,
int128_t a0, int128_t b0, int128_t c0, int print_mode, FILE* output);
#endif /* SOLVE_H */ #endif /* SOLVE_H */
+2 -2
View File
@@ -89,12 +89,12 @@ void generate_factor_pairs(int128_t* sum, int32_t prime_index, int32_t* exponent
if (is_new_root(r1a, r1b, r1c)) { if (is_new_root(r1a, r1b, r1c)) {
int128_t greater = max2(r1b, r1c); int128_t greater = max2(r1b, r1c);
LIMIT = r1a >= greater ? r1a * greater / 2 : r1b * r1c / 2; LIMIT = r1a >= greater ? r1a * greater / 2 : r1b * r1c / 2;
solve(sum, r1a, r1b, r1c, print_mode, output); solve(sum, gcd1, r1a, r1b, r1c, print_mode, output);
} }
if (val2 >= 0 && is_new_root(r2a, r2b, r2c)) { if (val2 >= 0 && is_new_root(r2a, r2b, r2c)) {
int128_t greater = max2(r2b, r2c); int128_t greater = max2(r2b, r2c);
LIMIT = r2a >= greater ? r2a * greater / 2 : r2b * r2c / 2; LIMIT = r2a >= greater ? r2a * greater / 2 : r2b * r2c / 2;
solve(sum, r2a, r2b, r2c, print_mode, output); solve(sum, gcd2, r2a, r2b, r2c, print_mode, output);
} }
} }
return; return;
+18 -3
View File
@@ -52,7 +52,8 @@ void try_push_children(Node* curr) {
} }
} }
static bool bfs(int128_t* sum, int128_t a0, int128_t b0, int128_t c0, int print_mode, FILE* output) { static bool bfs(int128_t* sum, int128_t gcd,
int128_t a0, int128_t b0, int128_t c0, int print_mode, FILE* output) {
node_pool_reset(); node_pool_reset();
queue_clear(); queue_clear();
clear_hash_table(); clear_hash_table();
@@ -122,6 +123,19 @@ static bool bfs(int128_t* sum, int128_t a0, int128_t b0, int128_t c0, int print_
fprint_int128(output, c0); fprint_int128(output, c0);
fprintf(output, ") the required amount of moves is: %i\n", max_moves); fprintf(output, ") the required amount of moves is: %i\n", max_moves);
} }
} else if (print_mode == 3) {
if (output) {
fprint_int128(output, a0 * gcd); fprintf(output, " ");
fprint_int128(output, b0 * gcd); fprintf(output, " ");
fprint_int128(output, c0 * gcd); fprintf(output, " ");
fprint_int128(output, max_moves); fprintf(output, " ");
fprint_int128(output, c0 * gcd); fprintf(output, " ");
fprint_int128(output, gcd2(a0 * gcd, c0 * gcd)); fprintf(output, " ");
fprint_int128(output, gcd2(b0 * gcd, c0 * gcd)); fprintf(output, " ");
fprint_int128(output, (c0 * gcd) % (b0 * gcd)); fprintf(output, " ");
fprint_int128(output, (c0 * gcd) % (a0 * gcd)); fprintf(output, " ");
fprintf(output, "\n");
}
} }
*sum += max_moves; *sum += max_moves;
@@ -132,7 +146,8 @@ static bool bfs(int128_t* sum, int128_t a0, int128_t b0, int128_t c0, int print_
return true; return true;
} }
bool solve(int128_t* sum, int128_t a0, int128_t b0, int128_t c0, int print_mode, FILE* output) { bool solve(int128_t* sum, int128_t gcd,
int128_t a0, int128_t b0, int128_t c0, int print_mode, FILE* output) {
/* Fallback to BFS */ /* Fallback to BFS */
return bfs(sum, a0, b0, c0, print_mode, output); return bfs(sum, gcd, a0, b0, c0, print_mode, output);
} }
+4 -3
View File
@@ -120,6 +120,7 @@ int main() {
while (print_mode == 0) { while (print_mode == 0) {
if (printf("1: Print full?\n") < 0) return 1; if (printf("1: Print full?\n") < 0) return 1;
if (printf("2: Print minimal?\n") < 0) return 1; if (printf("2: Print minimal?\n") < 0) return 1;
if (printf("3: Print debug?\n") < 0) return 1;
char* line = prompt_line("Choose what mode you want to enter: "); char* line = prompt_line("Choose what mode you want to enter: ");
if (!line) { if (!line) {
fprintf(stderr, "Input error.\n"); fprintf(stderr, "Input error.\n");
@@ -127,7 +128,7 @@ int main() {
} }
print_mode = atoi(line); print_mode = atoi(line);
free(line); free(line);
if (print_mode != 1 && print_mode != 2) print_mode = 0; if (print_mode != 1 && print_mode != 2 && print_mode != 3) print_mode = 0;
} }
if (mode == 1) { if (mode == 1) {
@@ -149,7 +150,7 @@ int main() {
int128_t greater = max2(b, c); int128_t greater = max2(b, c);
LIMIT = a >= greater ? a * greater : b * c; LIMIT = a >= greater ? a * greater : b * c;
solve(&sum, a, b, c, print_mode, f_output); solve(&sum, gcd, a, b, c, print_mode, f_output);
} else if (mode == 2) { } else if (mode == 2) {
clear_global_table(); /* Reset unique root tracker */ clear_global_table(); /* Reset unique root tracker */
int32_t p = 7; int32_t p = 7;
@@ -173,7 +174,7 @@ int main() {
if (is_new_root(ra, rb, rc)) { if (is_new_root(ra, rb, rc)) {
int128_t greater = max2(rb, rc); int128_t greater = max2(rb, rc);
LIMIT = ra >= greater ? ra * greater / 2 : rb * rc / 2; LIMIT = ra >= greater ? ra * greater / 2 : rb * rc / 2;
solve(&sum, ra, rb, rc, print_mode, f_output); solve(&sum, gcd, ra, rb, rc, print_mode, f_output);
} }
} }