Fixed the no output when given a pair that cannot be computed. Also added more debug information.
Stergios Upload Compile Checker / Explore-Gitea-Actions (push) Successful in 4s
Stergios Upload Compile Checker / Explore-Gitea-Actions (push) Successful in 4s
This commit is contained in:
4 files changed
+150
-16
No files matched your search
+19
-10
@@ -81,7 +81,11 @@ static bool bfs(int128_t* sum, int128_t gcd,
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
if (print_mode == 1) printf("No solution found.\n");
|
||||
fprintf(output, "No solution found for (");
|
||||
fprint_int128(output, a0); fprintf(output, ", ");
|
||||
fprint_int128(output, b0); fprintf(output, ", ");
|
||||
fprint_int128(output, c0);
|
||||
fprintf(output, ".\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -125,15 +129,20 @@ static bool bfs(int128_t* sum, int128_t gcd,
|
||||
}
|
||||
} 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, " ");
|
||||
int128_t a = a0 * gcd, b = b0 * gcd, c = c0 * gcd;
|
||||
int128_t k = mysqrt_uint128(a * a + b * b + c * c - 2 *a * b - 2 * b * c - 2 * c * a);
|
||||
fprint_int128(output, a); fprintf(output, " ");
|
||||
fprint_int128(output, b); fprintf(output, " ");
|
||||
fprint_int128(output, c); 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, " ");
|
||||
fprint_int128(output, gcd2(a, c)); fprintf(output, " ");
|
||||
fprint_int128(output, gcd2(b, c)); fprintf(output, " ");
|
||||
fprint_int128(output, c % b); fprintf(output, " ");
|
||||
fprint_int128(output, c % a); fprintf(output, " ");
|
||||
fprint_int128(output, k); fprintf(output, " ");
|
||||
fprint_int128(output, c - a - b - k); fprintf(output, " ");
|
||||
fprint_int128(output, c - a - b + k); fprintf(output, " ");
|
||||
fprintf(output, "%s", k < 2 * (int128_t)mysqrt_uint128(a * b) ? "True" : "False");
|
||||
fprintf(output, "\n");
|
||||
}
|
||||
}
|
||||
@@ -148,6 +157,6 @@ static bool bfs(int128_t* sum, int128_t gcd,
|
||||
|
||||
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 */
|
||||
/* Execute to BFS */
|
||||
return bfs(sum, gcd, a0, b0, c0, print_mode, output);
|
||||
}
|
||||
+11
-5
@@ -138,10 +138,10 @@ int main() {
|
||||
}
|
||||
|
||||
if (a0 == 0 || b0 == 0 || c0 == 0) {
|
||||
printf("Already zero present: (");
|
||||
print_int128(a0); printf(", ");
|
||||
print_int128(b0); printf(", ");
|
||||
print_int128(c0); printf(")\n");
|
||||
fprintf(f_output, "Already zero present: (");
|
||||
fprint_int128(f_output, a0); fprintf(f_output, ", ");
|
||||
fprint_int128(f_output, b0); fprintf(f_output, ", ");
|
||||
fprint_int128(f_output, c0); fprintf(f_output, ")\n");
|
||||
return 0;
|
||||
}
|
||||
int128_t gcd = gcd3(a0, b0, c0);
|
||||
@@ -153,7 +153,13 @@ int main() {
|
||||
solve(&sum, gcd, a, b, c, print_mode, f_output);
|
||||
} else if (mode == 2) {
|
||||
clear_global_table(); /* Reset unique root tracker */
|
||||
int32_t p = 7;
|
||||
char* line = prompt_line("Choose what exponential you want to use: ");
|
||||
if (!line) {
|
||||
fprintf(stderr, "Input error.\n");
|
||||
return 1;
|
||||
}
|
||||
int32_t p = atoi(line);
|
||||
free(line);
|
||||
int32_t exponents[3] = {2*p + 2, p, p};
|
||||
int128_t values[3] = {4 * power(a0, p) * power(b0, p), power(a0, p), power(b0, p)};
|
||||
generate_factor_pairs(&sum, 0, exponents, values, 1, print_mode, f_output);
|
||||
|
||||
Reference in new issue
Block a user