Created
April 29, 2011 14:11
-
-
Save amadamala/948353 to your computer and use it in GitHub Desktop.
Collatz sequence
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 = 1001 | |
def collatz_sequences(n): | |
while n > 1: | |
print n | |
if (n % 2) != 0: | |
n = (3 * n) + 1 | |
else: | |
n = n / 2 | |
print n | |
if __name__ == '__main__': | |
collatz_sequences(N) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment