Problem 002

A place to air possible concerns or difficulties in understanding ProjectEuler problems. This forum is not meant to publish solutions. This forum is NOT meant to discuss solution methods or giving hints how a problem can be solved.
Forum rules
As your posts will be visible to the general public you are requested to be thoughtful in not posting anything that might explicitly give away how to solve a particular problem.

This forum is NOT meant to discuss solution methods for a problem.

In particular don't post any code fragments or results.

Don't start begging others to give partial answers to problems

Don't ask for hints how to solve a problem

Don't start a new topic for a problem if there already exists one


See also the topics:
Don't post any spoilers
Comments, questions and clarifications about PE problems.
mdean
Posts: 206
Joined: Tue Aug 02, 2011 2:05 am

Re: Problem 2: Even Fibonacci numbers

Post by mdean »

The problem states "by starting with 1 and 2, the first 10 terms will be..."
Image
pcworx
Posts: 6
Joined: Wed Nov 27, 2013 3:52 pm

Re: Problem 002

Post by pcworx »

This maybe a dumb question but on problem 2 what do you start with for the 1st number in your loop?

Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:
1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.


The problem clearly states to start with 1 and 2, but when it says the first 10 terms will be 1,2,3,5..........
the only way to get the terms 1 and 2 are to start with 0 correct? start with 0 would result in this set of fibo's: 0,1,2,3,5,8........ 0+1=1, 1+1=2, 1+2=3, 2+3=5, 3+5=8........ and so on. Or are 1 and 2 just assumed to be the first fibo's and therefore 2 would be the first number that would be added to get the sum of the positive fibo's? Maybe I am reading to much into it?

Thanks,
Dan
User avatar
nicolas.patrois
Posts: 118
Joined: Fri Jul 26, 2013 4:54 pm
Contact:

Re: Problem 002

Post by nicolas.patrois »

It’s problem #2, you should not search too far away.
Image
User avatar
dawghaus4
Posts: 56
Joined: Fri Nov 29, 2013 2:22 am

Re: Problem 002

Post by dawghaus4 »

pcwork,

I don't like the statement in the problem that "the" Fibonacci sequence starting with 1 and 2 …, since "the" Fibonacci sequence starts with 1 and 1. Regardless, the answer would not change.

Note, the Fibonacc sequence is usually defined recursively. As all recursive definitions, starting value(s) have to be given. Since the definition is that each term is given by adding the two previous terms, two starting values have to be given. Here, they were given to be 1 and 2. But, again, it does not matter whether or not you start with 1 and 1 or with 1 and 2, the sum of the even Fibonacci numbers that do not exceed 4 million will be the same.

As a tease, it is possible to get the answer without adding them!
pcworx
Posts: 6
Joined: Wed Nov 27, 2013 3:52 pm

Re: Problem 002

Post by pcworx »

Thanks guys,

Seems my algorithm in my head for the math was correct it was just my algorithm for the python code wasn't quite correct. Fixed that up and solved the problem with no cheating! Well I asked my father but he's a chemist and 84 so that doesn't really count and he tried to get me to do sub-scripted variables using quick basic......but anyways thanks for taking time to look at my question.

Dan
infinitecampus
Posts: 2
Joined: Wed Feb 12, 2014 10:07 pm

Re: Problem 002

Post by infinitecampus »

can someone look at my code and explain to me why i seem to get a negative number? i'm using bluej (java). thanks
User avatar
mpiotte
Administrator
Posts: 1961
Joined: Tue May 08, 2012 5:40 pm
Location: Montréal, Canada

Re: Problem 002

Post by mpiotte »

When computing positive numbers, negative results are often the sign of an overflow problem. When an integer variable increases above its maximum range, the result will appear as a negative number. In this problem, we are only interested in relatively small numbers, so there should be no overflow, unless there is a bug.
Image
infinitecampus
Posts: 2
Joined: Wed Feb 12, 2014 10:07 pm

Re: Problem 002

Post by infinitecampus »

Thank you very much! Solved it in a pinch thanks to that!
adhirramjiawan
Posts: 1
Joined: Sat Nov 01, 2014 4:11 pm

Re: Problem 002

Post by adhirramjiawan »

rjgonza wrote:I am having a little trouble with this one. I think I may be interpreting the question incorrectly. The value in question is the actual terms of the sequence, not the corresponding position in the sequence correct? If that is the case then I am not sure why my code is not working. Would I be able to pm it to someone to give it a quick glance?
I've also struggled with this a bit. The value of the Fibonacci number must not exceed 4 million.
User avatar
Ike
Posts: 1
Joined: Wed Nov 12, 2014 11:56 pm

Re: Problem 002

Post by Ike »

I was also initially confused by the wording of this problem. I first thought that the answer would be the sum of four million numbers of the sequence rather than the sum of all of the numbers in the sequence under four million. I got it now though!
Image

"I have no special talents, I am just passionately curious." - A.E.
venomnert
Posts: 2
Joined: Fri Mar 04, 2016 7:34 pm

Re: Problem 002

Post by venomnert »

I am sorry if I my response violates any kind of rule. Please excuse me since this is my first time posting.

I was wondering if it is possible to solve the problem using iteration?
v6ph1
Posts: 134
Joined: Mon Aug 25, 2014 7:14 pm

Re: Problem 002

Post by v6ph1 »

venomnert wrote:I was wondering if it is possible to solve the problem using iteration?
Why not? - Iterate through the list of Fibonacci numbers.
You can solve this problem using a lot of different algorithms.
Image
kraapi
Posts: 1
Joined: Wed Jun 22, 2016 7:15 pm

Re: Problem 002

Post by kraapi »

Hello,

I'm quite a beginner in programming, I can programme simple stuff but no complex algorithms. So the problem I come across is that, I managed to count the Fibonacci sequence from 1 to 10. It was quite a pain in my a** to figure it out. And I can count the sequence even further. I managed it with swapping variables. My problem is that I don't really understand what I have to do for this problem. I assume, that I need to find even numbers that are under 4 million in the Fibonacci sequence. And then sum them together. So in my theory the sequence has to stop at somewhere 4 million. To find the even numbers is simple, I just have to look up which numbers divide by 2 and add them together for the sum. But I can't figure it out which numbers should be used for the sum.

Best Regards

EDIT: I found the solution for this problem. It was much easier than I thought. I read this thread severals times through :D And I found the answer to my problem, here :D Some times is the answer beneath your nose, used my grandma to say :D

-kraapi
mafridi
Posts: 4
Joined: Mon Oct 22, 2018 7:24 pm

Re: Problem 002

Post by mafridi »

Hi,

I solved this problem using python but I'm also trying to learn the formula. If the example provides us with 1 2 3 5 8 13 21 34 55 89 144, can someone please PM me how the formula which is provided in the answer would be filled out? Instead of using 4 million as the threshold for a value lets just use 200 as an example.

I read the WikiPedia on Fibonacci numbers but don't understand how the formula is being used. I just want to see what the filled out formula looks like so I can better understand it.

Thank you.
User avatar
kenbrooker
Posts: 187
Joined: Mon Feb 19, 2018 3:05 am
Location: Northern California, USA

Re: Problem 002

Post by kenbrooker »

mafridi...

Please see PM from me...
"Good Judgment comes from Experience;
Experience comes from Bad Judgment
..."
Image
Post Reply