def collatz(n): steps = 1 #Because the number itself is the first in the sequence. while n!=1: if n%2: n = (3*n+1)/2 steps+=2 else: n /= 2 steps+=1 return steps for n in range(1, 10**9): ''' This is the main loop that tests every number. The last number it looks up for is the second number in the range() function - 1, in the example it would be 10^9-1 ''' if collatz(n)>n: print str(n)+',', print