Jump to content

Project Euler 14

Wictorian

This says o isn't an int therefore it cant be ordered. Do you know why?

i = 2
o = 0
chain = 0
number = 0
def collatz(x):
    if x % 2 == 0:
        return (x/2)
    else:
        return (x*3+1)
def sequences(x):
    a = 1
    x = collatz(x)
    a += 1
    if x == 1:
        return(a)
while(i<1000000):
    o = sequences(i)
    if o > chain:
        chain = o
        number = i
    i+=1

i = 2
o = 0
chain = 0
number = 0
def collatz(x):
    if x % 2 == 0:
        return (x/2)
    else:
        return (x*3+1)
def sequences(x):
    a = 1
    x = collatz(x)
    a += 1
    if x == 1:
        return(a)
while(i<1000000):
    o = sequences(i)
    if o > chain:
        chain = o
        number = i
    i+=1

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

def sequences(x):
    a = 1
    x = collatz(x)
    a += 1
    if x == 1:
        return(a)

this doesn't return anything if x is not 1 so when you run

    o = sequences(i)

you only get an integer if collatz(i) is 1. Otherwise it's None which can't be compared with an integer..

Don't ask to ask, just ask... please 🤨

sudo chmod -R 000 /*

Link to comment
Share on other sites

Link to post
Share on other sites

19 hours ago, Sauron said:

def sequences(x):
    a = 1
    x = collatz(x)
    a += 1
    if x == 1:
        return(a)

this doesn't return anything if x is not 1 so when you run


    o = sequences(i)

you only get an integer if collatz(i) is 1. Otherwise it's None which can't be compared with an integer..

Thanks, I should have put a loop there.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×