Nov-18-2020, 07:34 PM
I tried to find the longest starting value less than 100,000 in a Collatz Sequence. Actually, I have two questions:
1)Output is 77,031, is this correct?
2)How can I find how many elements are there in the sequence that I found?
1)Output is 77,031, is this correct?
2)How can I find how many elements are there in the sequence that I found?
def sequence_number(n):
term = 1
while n > 1:
if n % 2 == 0:
n = n/2
else:
n = 3 * n+1
term += 1
return term
def starting_number():
t = 0
x = 1
while x < 100000:
if sequence_number(x) > t:
t = sequence_number(x)
value = x
x += 1
return value
print("It starts with the number:", starting_number())
