Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

002/fibonacci.js #4

Open
eliane-meltzer opened this issue Oct 22, 2017 · 1 comment
Open

002/fibonacci.js #4

eliane-meltzer opened this issue Oct 22, 2017 · 1 comment

Comments

@eliane-meltzer
Copy link

eliane-meltzer commented Oct 22, 2017

Shouldn't line 4 should read while(f[0] <= 4e6) ?

Your code yields the right answer for an input of 4 million, but consider the fibonacci numbers not exceeding 8.

Even fibonaccis would be 2 and 8, resulting in a sum of 10. Your code would log 2 as the answer.

@edoardo-p
Copy link

Technically yes, but this is only a problem if the bound is a Fibonacci number itself. In your example, 8 was a Fibonacci number so it got excluded from the sum, but 4,000,000 isn't so the answer will still be right.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants