fork download
  1. def Collatz(x):
  2. yield x
  3. while(x!=1):
  4. if(x & 1 == 1):
  5. x = x*3+1
  6. yield x
  7. else:
  8. x = x >> 1
  9. yield x
  10.  
  11. for x in Collatz(13): print x
Success #stdin #stdout 0.09s 8672KB
stdin
Standard input is empty
stdout
13
40
20
10
5
16
8
4
2
1