Created
April 22, 2019 17:52
-
-
Save mustooch/65ea1cd722e244f4f0836b83b313e5f6 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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