repl.it
@FuyuWinter/

Hailstone Sequence

Python 2.7

No description

fork
loading
Files
  • main.py
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
n = input("N: ")
h = [n]
length = 0
while True:
  if n % 2 == 0:
    n /= 2
    length += 1
  else:
    n *= 3
    n += 1
    length += 1

  h.append(n)

  if n == 1:
    length += 1
    print h
    print("Length: %s" % length)
    break
Fetching token
?