Fonction d' Akerman
Résolu
MOUNIRDD
Messages postés
1
Statut
Membre
-
_Ritchi_ Messages postés 22345 Statut Contributeur -
_Ritchi_ Messages postés 22345 Statut Contributeur -
Bonjour,
si'l vous plais, j ais besoin d 'un code itératif de la fonction d' Akermane
merci
si'l vous plais, j ais besoin d 'un code itératif de la fonction d' Akermane
merci
A voir également:
- Fonction ackermann python
- Fonction si et - Guide
- Citizen code python avis - Accueil - Outils
- Fonction miroir - Guide
- Fonction moyenne excel - Guide
- Python est introuvable. exúcutez sans argument pour procúder ó l - Forum Python
2 réponses
#! /usr/bin/python
def ackermann(m,n, verbose = False):
"""computes the value of an ackermann function for the input integers m and n
the ackermann function being
A(m,n)=n+1 if m=0
=A(m-1,1) if m>0 and n=1
=A(m-1,A(m,n-1) if m>0 and n>0"""
if m == 0 :
if verbose :
print (n+1)
return n+1
elif n == 0 :
if verbose :
print ("ackermann(%d , %d)" % ( m - 1, 1) )
return ackermann(m-1, 1)
else :
if verbose :
print ("ackerman(%d, ackermann(%d, %d)" % (m - 1, m, n - 1) )
return ackermann(m - 1,ackermann(m, n - 1))
print(ackermann(3, 5))
Attention, cette fonction est récursive et rapidement exponentielle !
Joli code !
Ritchi