Created
April 14, 2019 18:40
-
-
Save mflatischler/87678bac8bcf97fbefaa6bf2dc64e687 to your computer and use it in GitHub Desktop.
Collatz Conjencture 63728127 949 Steps
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
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