tags:

views:

65

answers:

3

Ackermann's Function is a recursive mathematical algorithm that can be used to test how well a computer performs recursion. Design a function ackermann(m,n), which solves Ackermann's Function. Use the following logic in your function:

If m = 0, then return n + 1  
If n = 0 then return ackermann(m-1, 1)  
Otherwise, return ackermann(m-1, ackermann(m, n-1))  

The program stops after it hits 13. Can anyone tell me what I have done wrong?

declare main()
declare ackermann(m:int, n:int)

openconsole
main()
print:print "Press any key to quit...",
do:until inkey$<>""
closeconsole
end

sub main()
 def counter, m, n:int
 counter = 0
 for counter = 1 to 100
  print ackermann(counter)
 next counter
return

sub ackermann(m, n)
 if m = 0
  return = n + 1
 else
  if n = 0
   return = ackermann(m - 1, 1)
  else
    return = ackermann(m - 1, ackermann(m, n - 1))
  endif
endif
return
+1  A: 

Your print statement is

print ackermann(counter)

but your function is

sub ackermann(m, n)

You need to send a second parameter in the first call.

Lance Roberts
I saw that too; but I'm really curious as to how it got to 13 but couldn't continue if that's the cause of the error.
overslacked
yeh, I've been trying find IBasic syntax on the web so I could see what's up with that, but all I can find is cheap download sites, no real info anywhere.
Lance Roberts
+1  A: 

Do note that Ackermann's function grows incredibly quickly - values above m,n > (3,4) are going to have a LOT of digits and if you go more than even about (4,4) you'll quickly find numbers that could quite possibly fill up your memory entirely with digits...

Refer to Wikipedia to see the magnitude of the numbers you are trying to compute...

Steven Schlansker
A: 
declare main()
declare ackermann(m:int, n:int)


openconsole
main()
print:print "Press any key to quit...",
do:until inkey$<>""
closeconsole
end

sub main()
print  Ackermann(3,5)
return

sub ackermann(m, n)
    if m = 0
     return = n + 1
    else
     if n = 0
      return = ackermann(m - 1, 1)
     else
       return = ackermann(m - 1, ackermann(m, n - 1))
     endif
    endif
return
Tara