I picked up some Project Euler questions today and decided to find more effective ways to Answer the questions l had already answered.
So on the question about finding the sum of the even Fibonacci terms up to 4 million; I noticed that if we had a separate sequence for the even Fibonacci terms (starting with 0 & 2 as the first & second terms respectively), the progression would be
If two values from two successive terms are known, then the next term could be gotten with this expression:
[ T(n) = (4 * T(n-1)) + T(n-2) ] ... Where; T(n) : is the nth term, T(n-1) : is the (n-1)th term, T(n-2) : is the (n-2)th term, and '4' is a constant.
However, so far I've been unable to derive an adequate expression to find the value in an arbitrary position without knowing the values of the two preceding terms.
Is this how equations (/algorithms) are derived?
Is this an efficient algorithm?
Footnote: The other less efficient method (in my opinion), is to:
Create a function to generate all the numbers in the Fibonacci sequence under 4 million,
Get the even numbers among them,
Find their sum.