Post Reply 
Help With Python?
07-17-2024, 07:07 PM
Post: #3
RE: Help With Python?
Another alternative to ldesnogu approach is to use an AI to convert the code.
This gives this which seem to work. At least it runs without an error.

Code:

import time

# Initialize variables
t0 = time.time()
Y = 30000
List1 = [0] * (Y + 1)
L = 0

# Loop from 1 to 999999
for N in range(1, 1000000):
    M = N
    C = 0
    while M != 1:
        if M % 2 == 0:
            M = M // 2
        else:
            M = 3 * M + 1
        C += 1
        if M <= Y:
            if List1[M] != 0:
                C += List1[M]
                M = 1
    if N <= Y:
        if List1[N] == 0:
            List1[N] = C
    if C > L:
        L = C
        print(N)
        print(C)

print(f"{time.time() - t0} seconds")
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Help With Python? - toml_12953 - 07-17-2024, 05:38 PM
RE: Help With Python? - ldesnogu - 07-17-2024, 05:52 PM
RE: Help With Python? - toml_12953 - 07-18-2024, 03:30 AM
RE: Help With Python? - pascal_meheut - 07-17-2024 07:07 PM



User(s) browsing this thread: 1 Guest(s)