1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
// 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++; }
put_n(s); put_c(' ');
put_n(lone); put_c(' ');
lone++;
}
put_n(lone); put_c(' ');
put_n(ack(2, 3)); put_c(' ');
put_n(many(1, 2, 3)); put_c(' ');
put_n(mix(100)); put_c(' ');
put_n(dyn(50)); put_c(' ');
put_n(pts(30)); put_c(' ');
put_n(divs(1000)); put_c(' ');
put_n(divs(-77)); put_c(10);
return 0;
}
|