For my extra credit, I'm supposed to generate the longest chain from 1-1000000, I wan't to know if it is correct..here is my code:
the caller

start = 1
            end = 1000000
            longest, chain = -1, -1
            #choiceX(start)
            for i in range((end-start)+1):
                if choiceX(start) > longest:
                    longest=start
                    chain=choiceX(start)
                start+=1
            print longest, "had the longest chain", chain

and the function

def choiceX( start ):
    number = start
    length = 1
    
    while number != 1:
        if number % 2 == 0:
            number /= 2
        else:
            number = (number*3) + 1
        length += 1

    return length

my output was "35655 had the longest chain 324"

Took around 1 min to generate

For my extra credit, I'm supposed to generate the longest chain from 1-1000000, I wan't to know if it is correct..here is my code:
the caller

start = 1
            end = 1000000
            longest, chain = -1, -1
            #choiceX(start)
            for i in range((end-start)+1):
                if choiceX(start) > longest:
                    longest=start
                    chain=choiceX(start)
                start+=1
            print longest, "had the longest chain", chain

and the function

def choiceX( start ):
    number = start
    length = 1
    
    while number != 1:
        if number % 2 == 0:
            number /= 2
        else:
            number = (number*3) + 1
        length += 1

    return length

my output was "35655 had the longest chain 324"

Took around 1 min to generate

I think it's correct.

This article has been dead for over six months. Start a new discussion instead.