Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- # -*- coding: utf-8 -*-
- #----------------------------------------------------------------------------
- # Created by : Alain Van Kerckhoven
- # Created Date: 7 juin 2018
- # Licence : GPL
- # Version : 1.0
- # ---------------------------------------------------------------------------
- """
- Collatz conjecture
- Donne la suite produite, le nombre d'itérations et le maximum trouvé pour
- un nombre soumis à la conjecture de Syracuse
- """
- # ---------------------------------------------------------------------------
- n = int(input("Entrez un nombre entier : "))
- i = 0 # Compteur
- vmax = 0 # Maximum atteint
- suite = []
- print ("Suite : ", end="")
- while (n>1):
- i+=1
- if(n%2==0): #si pair
- n = int(n/2)
- else:
- n = n*3+1
- suite.append(int(n))
- if (n>vmax):
- vmax = n
- print (suite)
- print ("Itérations :", i)
- print ("Maximum :", int(vmax))
Add Comment
Please, Sign In to add comment