Re: ackerman function

34 views
Skip to first unread message

catafest

unread,
Mar 28, 2013, 4:39:15 PM3/28/13
to Python Romania
Conform wikipedia :

In computability theory, the Ackermann function, named after Wilhelm
Ackermann, is one of the simplest and earliest-discovered examples of
a total computable function that is not primitive recursive. All
primitive recursive functions are total and computable, but the
Ackermann function illustrates that not all total computable functions
are primitive recursive.
Intelegi conceptul ?
Uite si un exemplu luat de pe : vezi aici :
http://stackoverflow.com/questions/12678099/ackermann-function-understanding

def A(m, n, s="%s"):
print s % ("A(%d,%d)" % (m, n))
if m == 0:
return n + 1
if n == 0:
return A(m - 1, 1, s)
n2 = A(m, n - 1, s % ("A(%d,%%s)" % (m - 1)))
return A(m - 1, n2, s)

print A(2,2)

Matei Trusca

unread,
Mar 28, 2013, 4:47:59 PM3/28/13
to python-...@googlegroups.com
2013/3/28 corin craciun <craciu...@gmail.com>:
> def ack(m,n):
> if m == 0:
> result = n+1
> print(result)
> return result
> elif m > 0 and n == 0:
> ack(m-1,float(1,1))
float(1,1) - float acceptă un singur parametru;
nu știu ce încercai să faci exact, dar de ce nu ack(m-1, 1) ?
> else m > 0 and n > 0:
> ack(m-1,ack(m,n-1))
>
> ack(3, 4)
>
>
> imi poate spune cineva unde am gresit?
>

corin craciun

unread,
Mar 28, 2013, 6:08:58 PM3/28/13
to python-...@googlegroups.com
da, si acolo era o greseala pe care am corectat-o :)
Reply all
Reply to author
Forward
0 new messages