[TP 3] Fin.
This commit is contained in:
parent
501e22da33
commit
f40fd76d7f
33
TP3/main.py
33
TP3/main.py
@ -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
|
BIN
TP3_bonus/TP3 instructions conditionnelles bonus.pdf
Normal file
BIN
TP3_bonus/TP3 instructions conditionnelles bonus.pdf
Normal file
Binary file not shown.
1
TP3_bonus/main.py
Normal file
1
TP3_bonus/main.py
Normal file
@ -0,0 +1 @@
|
||||
|
Loading…
Reference in New Issue
Block a user