Uses 1059K of libraries. Click here for Pure Java version (6138L/31K).
1 | cprint { |
2 | srecord f_ackermann(BigInt a, BigInt b) implements VStack.Computable<BigInt> { |
3 | void step(VStack stack, O subComputationResult) { |
4 | if (!stack.hasSubResult()) { |
5 | if (a.equals(BigInt.ZERO)) |
6 | stack._return(plus(b, BigInt.ONE)); |
7 | else if (b.equals(BigInt.ZERO)) |
8 | stack.tailCall(new f_ackermann(a.subtract(BigInt.ONE), BigInt.ONE); |
9 | else |
10 | stack.push(new f_ackermann(a, minus(b, BigInt.ONE))); |
11 | } else |
12 | stack.tailCall(new f_ackermann(minus(a, BigInt.ONE), subComputationResult/BigInt)); |
13 | } |
14 | } |
15 | |
16 | start-thread { |
17 | print("Result: " + vStackComputeWithStats(new f_ackermann(bigInt(2), bigInt(2)))); |
18 | |
19 | // detailed run |
20 | VStack stack = new(new f_ackermann(bigInt(2), bigInt(2))); |
21 | printStruct(stack); |
22 | while ping (stack.step()) { |
23 | printStruct(stack); |
24 | stack = restructure(stack); // persist to string and re-create |
25 | } |
26 | } |
27 | } |
Began life as a copy of #1030378
download show line numbers debug dex old transpilations
Travelled to 4 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, vouqrxazstgt
No comments. add comment
Snippet ID: | #1030379 |
Snippet name: | Turn Ackermann function into a virtual stack [even more memory-compact version without currentStep field] |
Eternal ID of this version: | #1030379/9 |
Text MD5: | c60903f5e18e3a00b7912c6eba1efe59 |
Transpilation MD5: | f3e461c937b69145c31e2e75c866fba7 |
Author: | stefan |
Category: | javax / maths |
Type: | JavaX source code (Dynamic Module) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2021-04-18 14:53:03 |
Source code size: | 953 bytes / 27 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 207 / 325 |
Version history: | 8 change(s) |
Referenced in: | [show references] |