Debian Codegraph @

demo/kitchen-sink/docs/scrypt.scrypt

raw
1 // https://github.com/sCrypt-Inc/boilerplate/blob/master/contracts/ackermann.scrypt
2
3 contract Ackermann {
4 int a; // a = 2
5 int b; // b = 1
6
7 static const int LOOPCOUNT = 14;
8
9 function ackermann(int m, int n) : int {
10 bytes stk = num2bin(m, 1);
11
12 // run this function off chain to get the loop count and set it here
13 // e.g., (2, 1) requires 14 loops, (3, 5) 42438
14 loop (LOOPCOUNT) {
15 if (len(stk) > 0) {
16 bytes top = stk[0 : 1];
17 m = unpack(top);
18
19 // pop
20 stk = stk[1 : len(stk)];
21
22 if (m == 0) {
23 n = n + m + 1;
24 }
25 else if (n == 0) {
26 n++;
27 m--;
28 // push
29 stk = num2bin(m, 1) + stk;
30 }
31 else {
32 stk = num2bin(m - 1, 1) + stk;
33 stk = num2bin(m, 1) + stk;
34 n--;
35 }
36 }
37 }
38
39 return n;
40 }
41
42 // y = 5
43 public function unlock(int y) {
44 require(y == this.ackermann(this.a, this.b));
45 }
46 }