[TP 3] Fin.

This commit is contained in:
Suwako Moriya 2019-11-24 01:10:23 +01:00
parent 501e22da33
commit f40fd76d7f
Signed by: SuwakoMmh
GPG Key ID: A27482B806F13CD5
3 changed files with 32 additions and 2 deletions

View File

@ -123,13 +123,15 @@ def binomes(n):
def syracuse(n):
if n%2:
return 3*n + 1
return n/2
return n>>1
def NbrEtapes(n):
def NbrEtapes(n, quiet=True):
l=n
i=0
while l!=1:
if not quiet:
print(l)
l=syracuse(l)
i+=1
return i
@ -138,5 +140,32 @@ def printNbrEtapes(n):
print(a)
return a
def test(n):
for i in range(n):
print(NbrEtapes(3**i), NbrEtapes(3**i + 1))
#Exercice bonus : Palindromes et nombres de Lychrel
def palindrome(l):
return l == l[::-1]
def ldec(n):
return list(map(int, str(n)))
def NbrPal(N):
#Methode ~bourrin~:
return sum([palindrome(ldec(i)) for i in range(N)])
def f(n):
return n + int(str(n)[::-1])
def hauteur(n):
N = n
c = 0
while not palindrome(ldec(N)):
N = f(N)
c += 1
if c>4999 and c%5000==0 and not input("continuer ? (oui/non) >").lower().startswith('o'):
break
print(N)
return c

Binary file not shown.

1
TP3_bonus/main.py Normal file
View File

@ -0,0 +1 @@