Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def hailstone(p):
- """Takes input and continues to put in output if even does p//2 if odd 3p+1"""
- H = []
- while p != 1:
- H.append(p)
- if p > 0:
- if p%2 == 0:
- p = p//2
- elif p%2 == 1:
- p = 3*p+1
- else:
- return("Invalid Input")
- if p == 1:
- H.append(1)
- return(H)
- print("Problem 1")
- print(hailstone(1))
- print("Problem 2")
- print(hailstone(27))
- print("problem 3")
- maxLength = 0
- for n in range(1, 20001):
- l = hailstone(n)
- m = len(l)
- if m > maxLength:
- maxLength = m
- largestInteger = n
- print(largestInteger, maxLength)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement