Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- __author__ = 'Cyph3r'
- N = 10
- X = N
- stepCount = 1
- highestS = 0
- highestN = 0
- g = 0
- f = str(input("Please name new file: "))
- g = int(input("Limit to calculate to? "))
- text_file0 = open(f+".txt", "w")
- while N != g+1:
- if X == 1:
- text_file0.write(str(N)+":"+str(stepCount)+"\n")
- print(str(N)+" : "+str(stepCount))
- if stepCount > highestS:
- print("* "+str(N)+" : "+str(stepCount))
- highestS = stepCount
- highestN = N
- stepCount = 1
- N += 1
- X = N
- else:
- if X % 2 == 0:
- X /= 2
- stepCount += 1
- else:
- X = X * 3 + 1
- stepCount += 1
- else:
- print("Largest Collatz sequence with most terms = "+str(highestN)+" with "+str(highestS)+" terms!")
- text_file0.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement