Advertisement
thekin

Python - Hailstone Sequence

Oct 5th, 2018
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.25 KB | None | 0 0
  1. n = input("N: ")
  2. h = [n]
  3. length = 0
  4. while True:
  5.   if n % 2 == 0:
  6.     n /= 2
  7.     length += 1
  8.   else:
  9.     n *= 3
  10.     n += 1
  11.     length += 1
  12.  
  13.   h.append(n)
  14.  
  15.   if n == 1:
  16.     length += 1
  17.     print h
  18.     print("Length: %s" % length)
  19.     break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement