diff options
Diffstat (limited to 'docs/history/15-o3/code/tests/o3.zc')
| -rw-r--r-- | docs/history/15-o3/code/tests/o3.zc | 83 |
1 files changed, 0 insertions, 83 deletions
diff --git a/docs/history/15-o3/code/tests/o3.zc b/docs/history/15-o3/code/tests/o3.zc deleted file mode 100644 index 296d1d5..0000000 --- a/docs/history/15-o3/code/tests/o3.zc +++ /dev/null @@ -1,83 +0,0 @@ -// o3 regions: every kind of control flow, against the same code without o3 -struct pt { int x; int y; }; -int g = 3; -int sq(int x) { return x * x; } -o3 int collatz(int n) -{ - int steps = 0; - while (n != 1) { if (n % 2 == 0) n = n / 2; else n = 3 * n + 1; steps++; } - return steps; -} -o3 int ack(int am, int n) -{ - if (am == 0) return n + 1; - if (n == 0) return ack(am - 1, 1); - return ack(am - 1, ack(am, n - 1)); -} -o3 int many(int a, int b, int c) -{ - int dd = a + b, e = b + c, f = c + a, h = dd * e, i2 = e * f, j = f * dd, k = h + i2 + j, l = k / 7; - for (int t = 0; t < 5; t++) { dd += t; e -= t; f = f ^ t; l = l + dd * e - f; } - return dd + e + f + h + i2 + j + k + l; -} -o3 int mix(int n) -{ - int acc = 0; - for (int i = 0; i < n; i++) { - if (i % 3 == 0 && i % 5 == 0) acc += 15; - else if (i % 3 == 0 || i > 90) acc += 3; - else acc = acc + (i & 1 ? sq(i) : g); - switch (i % 4) { case 0: acc += 1; case 1: acc -= 2; default: acc = acc ^ 1; } - if (acc > 100000) break; - if (i == 7) continue; - acc = acc + i / 10 - i % 7 + (i << 2) - (i >> 1); - } - return acc; -} -o3 int dyn(int n) -{ - []int a = new([]int, n); - fixed []int f = new(fixed []int, n); - int s = 0; - for (int i = 0; i < len(a); i++) { a[i] = i * i; f[i] = n - i; } - for (int i = 0; i < n; i++) s = s + a[i] * f[i]; - free(d*a); free(d*f); - return s; -} -o3 int pts(int n) -{ - *pt p = new(pt); - int s = 0; - p->x = 1; p->y = 2; - for (int i = 0; i < n; i++) { p->x = p->x + p->y; p->y = p->x - p->y; s = s + p->x % 1000; } - free(d*p); - return s; -} -o3 int divs(int x) -{ - int s = 0; - for (int i = -50; i < 50; i++) s = s + (x + i) / 7 + (x + i) % 7 + (x - i) / -3 + i / 16 + i % 16; - return s; -} -fn main() -{ - o3 int lone = 2; - let r = 0; - lone = lone * 21; - o3 { - int i = 0, s = 0; - while (i < 100) { s = s + collatz(i + 1); i++; } - putn(s); putc(' '); - putn(lone); putc(' '); - lone++; - } - putn(lone); putc(' '); - putn(ack(2, 3)); putc(' '); - putn(many(1, 2, 3)); putc(' '); - putn(mix(100)); putc(' '); - putn(dyn(50)); putc(' '); - putn(pts(30)); putc(' '); - putn(divs(1000)); putc(' '); - putn(divs(-77)); putc(10); - return 0; -} |
