Last active
April 24, 2022 05:01
-
-
Save flare9x/95e4ed74321899670373c373de1373dc to your computer and use it in GitHub Desktop.
Collatz conjecture
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
function collatz(n::Int64)::Int64 | |
while(n != 1) | |
# base case | |
if n == 1 | |
break | |
end | |
# if even | |
if (n % 2 == 0) | |
n = Int64(n /2) | |
elseif (n % 2 != 0) | |
n = Int64(3 * n + 1) | |
end | |
print("\n this is n", n) | |
end | |
return n | |
end | |
collatz(3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment