Skip to content

Instantly share code, notes, and snippets.

@flare9x
Last active April 24, 2022 05:01
Show Gist options
  • Save flare9x/95e4ed74321899670373c373de1373dc to your computer and use it in GitHub Desktop.
Save flare9x/95e4ed74321899670373c373de1373dc to your computer and use it in GitHub Desktop.
Collatz conjecture
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