Problem #2

For questions about problems on the Project Euler web site. No spoilers. Please include the question number in the subject line of your post.

Problem #2

Postby yukardo » Fri Apr 15, 2016 12:17 pm

Hi Everybody,

I am working on the problem #2 of the Euler Project.

I think I have solved the problem, but when I run the code my PC get super slow and sometimes freezing.

I want to know if that has happened to somebody else.

I do not know if I can paste my code here.

Please tell me if I can paste my code.

I hope you can help me.

Thanks.
Last edited by Yoriz on Fri Apr 15, 2016 1:08 pm, edited 1 time in total.
Reason: First post lock.
yukardo
 
Posts: 3
Joined: Fri Apr 15, 2016 12:03 pm

Re: Problem #2

Postby micseydel » Fri Apr 15, 2016 4:39 pm

If it's freezing your computer, then it's not correct so I'd say it's not a spoiler. Thanks for being careful but we need to see the code :)

If you're really concerned, you can try to reproduce the problem with the same program structure but some of the Euler stuff removed. If you're not sure how to do that, don't worry too much about it.
Due to the reasons discussed here we will be moving to python-forum.io on October 1, 2016.

This forum will be locked down and no one will be able to post/edit/create threads, etc. here from thereafter. Please create an account at the new site to continue discussion.
User avatar
micseydel
 
Posts: 3000
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

Re: Problem #2

Postby ichabod801 » Sat Apr 16, 2016 12:56 am

I would add that with Project Euler, it is typically easy to write a program that will give you the right answer, but take forever to do so. The trick is generally to figure out how to get the right answer in a reasonable amount of time.
Due to the reasons discussed here we will be moving to python-forum.io on October 1st, 2016.
This forum will be locked down and no one will be able to post/edit/create threads, etc. here from thereafter. Please create an account at the new site to continue discussion.
ichabod801
 
Posts: 688
Joined: Sat Feb 09, 2013 12:54 pm
Location: Outside Washington DC

Re: Problem #2

Postby yukardo » Sun Apr 17, 2016 8:45 pm

Well, here is the code.

Code: Select all
def fibonacci(x, y, z):

    lista_fibo = []
    fin = 2
    suma 
= 1

    lista_fibo
.append(x)
    lista_fibo.append(y)

    while fin < z:
        
        next_number 
= lista_fibo[-2] + lista_fibo[-1]

        lista_fibo.append(next_number)

        impar = next_number % 2

        if impar 
!= 0 and next_number <= z:
            suma += next_number

        fin 
+= 1

        
"""if next_number >= z:
            del lista_fibo[-1] """

    #return suma
    
    return lista_fibo

= 1
= 2
= 4000000

print fibonacci
(x, y, z)


Please give me your opinion.

Thanks
Last edited by micseydel on Sun Apr 17, 2016 10:00 pm, edited 1 time in total.
Reason: Code tags.
yukardo
 
Posts: 3
Joined: Fri Apr 15, 2016 12:03 pm

Re: Problem #2

Postby ichabod801 » Sun Apr 17, 2016 10:50 pm

Your code is going through 4,000,000 fibonacci numbers. The problem is to go through fibonacci numbers that are less than or equal to 4,000,000.

Drop fin, and test the loop on next_number instead.

Also, you are supposed to sum even numbers. Your sum starts with one, which will make it automatically wrong.
Due to the reasons discussed here we will be moving to python-forum.io on October 1st, 2016.
This forum will be locked down and no one will be able to post/edit/create threads, etc. here from thereafter. Please create an account at the new site to continue discussion.
ichabod801
 
Posts: 688
Joined: Sat Feb 09, 2013 12:54 pm
Location: Outside Washington DC

Re: Problem #2

Postby yukardo » Mon Apr 18, 2016 11:31 am

Thanks ichabid801 for your help.

I was a wrong interpration of the problem.

But I can solve it.

Thanks for your help.
yukardo
 
Posts: 3
Joined: Fri Apr 15, 2016 12:03 pm


Return to Project Euler

Who is online

Users browsing this forum: No registered users and 1 guest

cron