diff options
| author | Tyge Løvset <[email protected]> | 2023-05-02 07:20:29 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2023-05-02 07:20:29 +0200 |
| commit | 2adea8b3b06ebe1b2152870862100f7e7985cfdf (patch) | |
| tree | 7d37dc14784f33e9b40888253aa5c7183d81c6b0 /misc/examples/triples.c | |
| parent | 399eb8d0e1de2839d826a9e0cf123d90d00b0018 (diff) | |
| download | STC-modified-2adea8b3b06ebe1b2152870862100f7e7985cfdf.tar.gz STC-modified-2adea8b3b06ebe1b2152870862100f7e7985cfdf.zip | |
Improved coroutine.h, added new coro examples.
Diffstat (limited to 'misc/examples/triples.c')
| -rw-r--r-- | misc/examples/triples.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/misc/examples/triples.c b/misc/examples/triples.c index 520bf012..2e0211c3 100644 --- a/misc/examples/triples.c +++ b/misc/examples/triples.c @@ -23,13 +23,13 @@ struct triples { int cco_state; }; -bool triples_next(struct triples* I) { +bool triples_coro(struct triples* I) { cco_begin(I); 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) { - cco_yield(true); + cco_yield(false); if (--I->n == 0) cco_return; } } @@ -37,7 +37,7 @@ bool triples_next(struct triples* I) { } cco_final: puts("done"); - cco_end(false); + cco_end(true); } int gcd(int a, int b) { @@ -58,7 +58,7 @@ int main() struct triples t = {INT32_MAX}; int n = 0; - while (triples_next(&t)) { + while (!triples_coro(&t)) { if (gcd(t.a, t.b) > 1) continue; if (t.c < 100) |
