[TP3_bonus] Questions 1 -> 3/b)

This commit is contained in:
Suwako Moriya 2019-11-25 03:46:18 +01:00
parent f40fd76d7f
commit 8880f7c0b9
Signed by: SuwakoMmh
GPG Key ID: A27482B806F13CD5

View File

@ -1 +1,52 @@
# Question 1:
def tempsdevol(c):
u, n = c, 0
while u != 1:
if u % 2:
u = 3*u + 1
else:
u = u//2
n += 1
return n
# Question 2
def altitude(c):
u, umax = c, c
while u != 1:
if u % 2:
u = 3*u + 1
else:
u = u//2
if u > umax:
umax = u
return umax
# Question 3
# a)
def tempsdarret(c):
u, n, nmax = c, 0, 0
while u != 1:
n += 1
if u % 2:
u = 3*u + 1
else:
u = u//2
if u >= c:
nmax = n
return nmax
# b)
import time
def verification(m):# m=1000000 -> 60 sec
start = time.time()
for c in range(2, m+1):
tempsdarret(c)
return time.time() - start