def collatz(k): if k == 1: return 0 elif k % 2 == 0: return 1 + collatz(k/2) else: return 1 + collatz(3*k+1)