Skip to content

Instantly share code, notes, and snippets.

@mflatischler
Created April 14, 2019 18:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mflatischler/87678bac8bcf97fbefaa6bf2dc64e687 to your computer and use it in GitHub Desktop.
Save mflatischler/87678bac8bcf97fbefaa6bf2dc64e687 to your computer and use it in GitHub Desktop.
Collatz Conjencture 63728127 949 Steps
n = 63728127
def collatz(n, step = 1):
def iseven(n):
return n / 2
def isodd(n):
return (3 * n) + 1
if n == (0 or 1):
if n == 1:
print(f"End. 1 reached.")
pass
elif n % 2 == 0:
print(f"[{step}] {iseven(n)}")
collatz(iseven(n), step + 1)
return
else:
print(f"[{step}] {isodd(n)}")
collatz(isodd(n), step + 1)
return
collatz(n)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment