syracuse.py
1 |
|
---|---|
2 |
|
3 |
def syracure_suivant(nombre): |
4 |
if nombre % 2 == 0: |
5 |
return nombre / 2 |
6 |
else:
|
7 |
return 3 * nombre + 1 |
8 |
|
9 |
|
10 |
def jusqu_a_un(nombre_initial): |
11 |
nombre_iteration = 0
|
12 |
nombre_courant = nombre_initial |
13 |
|
14 |
while nombre_courant != 1: |
15 |
nombre_courant = syracure_suivant(nombre_courant) |
16 |
nombre_iteration += 1
|
17 |
|
18 |
return nombre_iteration
|
19 |
|
20 |
|
21 |
for nombre in range(1, 1337 + 1): |
22 |
print("nombre initial", nombre,
|
23 |
"nombre d'itérarions avant 1", jusqu_a_un(nombre))
|