Advertisement
Guest User

Untitled

a guest
Sep 14th, 2020
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.17 KB | None | 0 0
  1. def collatz(n):
  2.   times = 0
  3.   while n != 1:
  4.     times += 1
  5.    
  6.     if n % 2 == 0:
  7.       n /= 2
  8.     else:
  9.       n *= 3
  10.       n += 1
  11.  
  12.   return times
  13.  
  14. collatz(11)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement