Skip to content

Instantly share code, notes, and snippets.

@mustooch
Created April 22, 2019 17:52
Show Gist options
  • Save mustooch/65ea1cd722e244f4f0836b83b313e5f6 to your computer and use it in GitHub Desktop.
Save mustooch/65ea1cd722e244f4f0836b83b313e5f6 to your computer and use it in GitHub Desktop.
def collatz(num):
num = float(num)
# base case
if num == 1 :
print(num)
return
# even
if num%2 == 0 :
print(num)
return collatz(num/2)
# odd
elif num%2 != 0 :
print(num)
return collatz(3*num+1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment