I recently saw an interesting Computerphile Video about the Ackermann function and tried to recreate it in R, here's what I came up with:
Ackermann <- function(m,n){
if (m == 0){
return(n+1)
} else if (m > 0 & n == 0){
return(Ackermann(m-1,1))
} else if (m > 0 & n > 0){
return(Ackermann(m-1,Ackermann(m,n-1)))
}
}
in the video, they implemented their own version of the code (in C, I think) and explained that it takes a massive amount of recursive computation for specific value pairs such as 4,1 and it took them 3 minutes to compute that value. If I try to recreate this in R with my algorithm I get a stack overflow:
Error: C stack usage 7971652 is too close to the limit
Is there a way to get the result for Ackermann(4,1) in R?