Created
September 27, 2021 02:01
-
-
Save oleoneto/3223f3d1e4a3082758f7919907cdf73d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
def compute_collatz(number): | |
if number % 2 == 0: | |
return number / 2 | |
return (number * 3 + 1) / 2 | |
def main(): | |
try: | |
number = int(sys.argv[1]) | |
except: | |
number = int(input("Pick a number: ")) | |
result = compute_collatz(number) | |
counter = 1 | |
print(f"{counter} :> {result}") | |
while result > 1: | |
counter += 1 | |
result = compute_collatz(result) | |
print(f"{counter} :> {result}") | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment