http://scratch.mit.edu/projects/Molybdenum/2617436
The wikipedia link on the Ackermann function is useful: http://en.wikipedia.org/wiki/Ackermann_function
This program calculates Ackermann(m,n) for given m and n. It doesn't use any optimizations (like Ack(1,n)=n+2), so the script is very simple. It works by exploiting this property:
Any Ackermann function calculation only will be like this (intermediately):
Ack(A,Ack(B, ... Ack(Y,Z) ) ... ) )
[Sorry, double parenthesis are changed due to scratchblocks or something.]
So the last number (Z in the example) is kept seperate, and all the others, because they are all in the first argument, are kept in a list.
Then, the bottom evaluation (Ack(Y,Z) in the example) is calculated with (item last of M) and N (the varible). When that is done, M is deleted and the result is put in N (in result 1 in wikipedia definition), M and N are modified (result 2), or an M is added, while the old bottom M and N are modified. (You didn't need to understand that sentence).
Say the result was ☺. ☺ will be put in place of Ack(Y,Z), and the resulting "end" will be Ack(X,☺). Then the cycle starts all over.
I have found that the stack is a good way to visualize the Ackermann function.
Comments?
Offline
Bump...
1. Why isn't anyone posting?
2. This is a good way to visualize the Ackermann function.
4. You didn't notice I skipped 3.
5. Why doesn't anyone post on my threads (as much as the others)?
Offline
This is pretty interesting!
Offline
Hmm... I didn't see these posts. Thanks for repling anyway!
Offline
Yes, recursion is interesting, but we have to wait for scratch 2.0 to do it in scratch
Offline