Python Forum
How can I found how many numbers are there in a Collatz Sequence that I found?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How can I found how many numbers are there in a Collatz Sequence that I found?
#1
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?

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())
Reply


Messages In This Thread
How can I found how many numbers are there in a Collatz Sequence that I found? - by cananb - Nov-18-2020, 07:40 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Random Generator: From Word to Numbers, from Numbers to n possibles Words Yamiyozx 2 1,521 Jan-02-2023, 05:08 PM
Last Post: deanhystad
Exclamation Homework( Solution found) Zaochen 2 1,925 Dec-23-2021, 04:18 PM
Last Post: BashBedlam
  Collatz-problem CaptainNeemo 2 2,292 Dec-07-2020, 04:09 PM
Last Post: deanhystad
  Convert list of numbers to string of numbers kam_uk 5 3,133 Nov-21-2020, 03:10 PM
Last Post: deanhystad
  Printing sequence of numbers kam_uk 1 2,891 Sep-27-2020, 01:50 PM
Last Post: perfringo
  How to update set of hash values until final hash value is found using the 5 hashes shakespeareeee 1 2,029 Jul-25-2019, 12:34 AM
Last Post: Larz60+
  [split] The Collatz Sequence valencia 4 3,775 Jan-06-2019, 08:10 PM
Last Post: valencia
  The Collatz Sequence Truman 11 14,347 Dec-27-2018, 11:28 PM
Last Post: Truman
  Trying to teach myself how to code and I'm stuck on a question I found online... abushaa4 1 2,267 Dec-16-2018, 01:52 PM
Last Post: ichabod801
  Dataload() crash when filename is not found Mark3232 1 1,996 Dec-08-2018, 10:23 AM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020