Find how many even Fibonacci numbers are available in the first d numbers.
Consider the following first 14 numbers
1 1 2 3 5 8 13 21 34 55 89 144 233 377 ...
4 of them are even.
Big number is a problem. Instead we can find the regular pattern in which those even and odd numbers appear. Then everything becomes simple and easy.
What's wrong with this?? It's working in matlab for me .
My code works to d=50 and fails on the higher values in the test suite. I think it is a hardware-limited rounding error (?swamping) with very large numbers. When I test eps(fibonacci(100)) on my system, the answer is 6.5 ie my system can not accurately distinguish odd from even at that large a number.
Leo, your theory is correct: The numbers that you're calculating for d>50 are too large to be represented by a 32-bit digit, and won't be calculated correctly for mod(x,2). Think very carefully about the number pattern in the Fibonacci sequence, and see if a pattern emerges.
Indeed, My code works until the d = 50 because it's a large number, so our algorithm is correct we should not worry about it, I think we have succeed in this challenge.
Not a true solution. Would fail if Test Suite were expanded.
Not a general solution. Will fail if Test Suite expanded.
Make a checkerboard matrix
Get the area codes from a list of phone numbers
7 segment LED display
Area of a triangle
Predicting life and death of a memory-less light bulb
Is there a GPU Device?
nth term of an infinite series
Fill the Matrix - 2
Determine if input is a valid AHP evaluation matrix
String permutations on phone keyboard
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Contact your local office