Skip to content

Instantly share code, notes, and snippets.

@lnsp
Created November 25, 2014 20:04
Show Gist options
  • Save lnsp/f0a7bd28afddd52a681c to your computer and use it in GitHub Desktop.
Save lnsp/f0a7bd28afddd52a681c to your computer and use it in GitHub Desktop.
Collatz algorithm implemented in Python 3.4
def collatz(x):
z = 0
while x != 1:
if x % 2 == 0:
x /= 2
else
x = x * 3 + 1
z += 1
return z
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment