diff --git a/TP3/main.py b/TP3/main.py index 4cb5f70..f730e8e 100644 --- a/TP3/main.py +++ b/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 \ No newline at end of file diff --git a/TP3_bonus/TP3 instructions conditionnelles bonus.pdf b/TP3_bonus/TP3 instructions conditionnelles bonus.pdf new file mode 100644 index 0000000..536f7be Binary files /dev/null and b/TP3_bonus/TP3 instructions conditionnelles bonus.pdf differ diff --git a/TP3_bonus/main.py b/TP3_bonus/main.py new file mode 100644 index 0000000..8d1c8b6 --- /dev/null +++ b/TP3_bonus/main.py @@ -0,0 +1 @@ +