07-16-2022, 03:09 PM
(This post was last modified: 07-16-2022, 03:22 PM by James D Jarvis.)
The original program certainly runs into a stack overflow due to the use of the recursive function.
I was able to calculate a(4,1) using the following code adapted from the basic256 version as that doesn't have recursive functions built in. I takes a couple minutes to calculate but it works. I have no idea if it can calculate A(4,2).
I was able to calculate a(4,1) using the following code adapted from the basic256 version as that doesn't have recursive functions built in. I takes a couple minutes to calculate but it works. I have no idea if it can calculate A(4,2).
Code: (Select All)
Dim stack(50000000, 3) As _Integer64
Dim lev, m, n, a, b As _Integer64
Input "1st #"; a
Input "2nd #"; b
stack(0, 0) = a
stack(0, 1) = b
lev = 0
GoSub ackermann
Print "A("; stack(0, 0); ","; stack(0, 1); ") ="; stack(0, 2)
End
ackermann:
If stack(lev, 0) = 0 Then
stack(lev, 2) = stack(lev, 1) + 1
Return
End If
If stack(lev, 1) = 0 Then
lev = lev + 1
stack(lev, 0) = stack(lev - 1, 0) - 1
stack(lev, 1) = 1
GoSub ackermann
stack(lev - 1, 2) = stack(lev, 2)
lev = lev - 1
Return
End If
lev = lev + 1
stack(lev, 0) = stack(lev - 1, 0)
stack(lev, 1) = stack(lev - 1, 1) - 1
GoSub ackermann
stack(lev, 0) = stack(lev - 1, 0) - 1
stack(lev, 1) = stack(lev, 2)
GoSub ackermann
stack(lev - 1, 2) = stack(lev, 2)
lev = lev - 1
Return