Click to See Complete Forum and Search --> : Ackermann Function


Student Stebel
October 29th, 2003, 01:14 PM
Hi

I'm just new to programming and started my studies towards it, so please don't get mad about my amateur question... :D

I need to put the ackermann function :

A(m ; n) =

= n+1 if m=0
= A(m-1 ; 1 ) if (m>0 and n=0)
= A(m-1 ; A(m ; n-1)) if else


in NOT recursive way.

Do you then have idea how to put it into iteration ??

I'd prefer pascal or ada95 code, but will also appreciate in C....
Presently I have no idea how to do it...

Many thanks

SolarFlare
October 29th, 2003, 09:14 PM
Originally posted by Student Stebel
Hi

I'm just new to programming and started my studies towards it, so please don't get mad about my amateur question... :D

I need to put the ackermann function :

A(m ; n) =

= n+1 if m=0
= A(m-1 ; 1 ) if (m>0 and n=0)
= A(m-1 ; A(m ; n-1)) if else


in NOT recursive way.

Do you then have idea how to put it into iteration ??

I'd prefer pascal or ada95 code, but will also appreciate in C....
Presently I have no idea how to do it...

Many thanks
The Ackermann function is by definition recursive. Since you don't know how many times it will call itself before knowing the first input, it has to be just one set of code for the function. So the only other thing is a loop, which is recursive in a sense, in that it calls itself when it completes.

So running through the loop, you can have the test conditions and subtract from the variables themselves then loop around again.