[TP 3] Exo Bonus - Syracuse
This commit is contained in:
parent
02c92aedeb
commit
501e22da33
24
TP3/main.py
24
TP3/main.py
@ -117,4 +117,26 @@ def binomes(n):
|
||||
for j in range(i):
|
||||
l.append(lastl.pop(0) + lastl[0])
|
||||
lastl=l+ [0]
|
||||
return(l)
|
||||
return(l)
|
||||
|
||||
#Exercice bonus : Conjecture de Syracuse
|
||||
def syracuse(n):
|
||||
if n%2:
|
||||
return 3*n + 1
|
||||
return n/2
|
||||
|
||||
|
||||
def NbrEtapes(n):
|
||||
l=n
|
||||
i=0
|
||||
while l!=1:
|
||||
l=syracuse(l)
|
||||
i+=1
|
||||
return i
|
||||
def printNbrEtapes(n):
|
||||
a=[NbrEtapes(i) for i in range(1, n+1)]
|
||||
print(a)
|
||||
return a
|
||||
|
||||
#Exercice bonus : Palindromes et nombres de Lychrel
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user