avkLab

Collatz conjecture

Jun 10th, 2022 (edited)
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.91 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. #----------------------------------------------------------------------------
  4. # Created by  : Alain Van Kerckhoven
  5. # Created Date: 7 juin 2018
  6. # Licence     : GPL
  7. # Version     : 1.0
  8. # ---------------------------------------------------------------------------
  9. """
  10. Collatz conjecture
  11. Donne la suite produite, le nombre d'itérations et le maximum trouvé pour
  12. un nombre soumis à la conjecture de Syracuse
  13. """
  14. # ---------------------------------------------------------------------------
  15.  
  16.  
  17. n = int(input("Entrez un nombre entier : "))
  18. i = 0 # Compteur
  19. vmax = 0 # Maximum atteint
  20. suite = []
  21.  
  22. print ("Suite : ", end="")
  23. while (n>1):
  24.     i+=1
  25.     if(n%2==0): #si pair
  26.         n = int(n/2)
  27.     else:
  28.         n = n*3+1
  29.     suite.append(int(n))
  30.     if (n>vmax):
  31.         vmax = n
  32.  
  33. print (suite)
  34. print ("Itérations :", i)
  35. print ("Maximum :", int(vmax))
  36.  
Add Comment
Please, Sign In to add comment