diff options
| author | Tyge Løvset <[email protected]> | 2023-04-05 14:44:31 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2023-04-05 14:44:31 +0200 |
| commit | 2ad41420a973a3f1bd1ca47ab0f61b8f59ab9e66 (patch) | |
| tree | 047454272a19544d0a99db7ca07394c81894b474 /misc/examples/triples.c | |
| parent | a3dc31d5393d051ad4dacb314452d3c6ec8a74b7 (diff) | |
| download | STC-modified-2ad41420a973a3f1bd1ca47ab0f61b8f59ab9e66.tar.gz STC-modified-2ad41420a973a3f1bd1ca47ab0f61b8f59ab9e66.zip | |
Internal: renamed untemplate.h to template2.h
Diffstat (limited to 'misc/examples/triples.c')
| -rw-r--r-- | misc/examples/triples.c | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/misc/examples/triples.c b/misc/examples/triples.c index aac7967a..520bf012 100644 --- a/misc/examples/triples.c +++ b/misc/examples/triples.c @@ -4,12 +4,12 @@ #include <stdio.h> void triples_vanilla(int n) { - for (int i = 5, c = 1;; ++c) { + for (int c = 5; n; ++c) { for (int a = 1; a < c; ++a) { for (int b = a + 1; b < c; ++b) { if ((int64_t)a*a + (int64_t)b*b == (int64_t)c*c) { - if (i++ == n) goto done; printf("{%d, %d, %d}\n", a, b, c); + if (--n == 0) goto done; } } } @@ -25,12 +25,12 @@ struct triples { bool triples_next(struct triples* I) { cco_begin(I); - for (I->c = 5;; ++I->c) { + for (I->c = 5; I->n; ++I->c) { for (I->a = 1; I->a < I->c; ++I->a) { for (I->b = I->a + 1; I->b < I->c; ++I->b) { if ((int64_t)I->a*I->a + (int64_t)I->b*I->b == (int64_t)I->c*I->c) { - if (I->n-- == 0) cco_return; cco_yield(true); + if (--I->n == 0) cco_return; } } } @@ -61,7 +61,7 @@ int main() while (triples_next(&t)) { if (gcd(t.a, t.b) > 1) continue; - if (t.c < 1000) + if (t.c < 100) printf("%d: {%d, %d, %d}\n", ++n, t.a, t.b, t.c); else cco_stop(&t); |
