Uses 911K of libraries. Click here for Pure Java version (2478L/13K).
cprint { sclass f_ackermann implements VStack.Computable<BigInt> { BigInt a, b; int currentStep; // 0 in the beginning, goes up to 1 *(BigInt *a, BigInt *b) {} void step(VStack stack, O subComputationResult) { if (currentStep == 0) { if (a.equals(BigInt.ZERO)) stack._return(plus(b, BigInt.ONE)); else if (b.equals(BigInt.ZERO)) stack.tailCall(new f_ackermann(a.subtract(BigInt.ONE), BigInt.ONE); else { stack.push(new f_ackermann(a, minus(b, BigInt.ONE))); currentStep = 1; } } else if (currentStep == 1) stack.tailCall(new f_ackermann(minus(a, BigInt.ONE), subComputationResult/BigInt)); else fail(); } } start-thread { print("Result: " + vStackComputeWithStats(new f_ackermann(bigInt(2), bigInt(2)))); } }
Began life as a copy of #1030375
download show line numbers debug dex old transpilations
Travelled to 4 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, vouqrxazstgt
No comments. add comment
Snippet ID: | #1030378 |
Snippet name: | Turn Ackermann function into a virtual stack [memory-compact version plus tail calls, shortened] |
Eternal ID of this version: | #1030378/3 |
Text MD5: | 0a9acb1aa8265df8328984ee713acedb |
Transpilation MD5: | d94c96a5f578d3286a3cc2c8a86f6e9d |
Author: | stefan |
Category: | javax / maths |
Type: | JavaX source code (Dynamic Module) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2020-12-10 14:15:52 |
Source code size: | 873 bytes / 27 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 193 / 279 |
Version history: | 2 change(s) |
Referenced in: | #1030379 - Turn Ackermann function into a virtual stack [even more memory-compact version without currentStep field] |