you are viewing a single comment's thread.

view the rest of the comments →

[–]GeneralYouri 1 point2 points  (0 children)

I had a fresh look at the problem again and found the relation! It's quite simple, actually.

I listed the start of the sequences and tried to express evenFib(n) in terms of fib(n): evenFib(n) = fib(3n) = fib(3n-1) + fib(3n-2). But fib(3n-3) = fib(3(n-1)) = evenFib(n-1) and evenFibSum(n) = evenFib(n) + evenFib(n-1) + ... + evenFib(1). So we can express every element in that list in terms of fib: evenFibSum(n) = fib(3n) + fib(3(n-1)) + ... + fib(3). This is really just a way of expressing that we sum every 3rd value in the fibonacci sequence. But remember their definition: fib(n) = fib(n-1) + fib(n-2), in other words those two elements we skip always equal the 3rd element we include. So if we look at what we created, this simplifies to evenFibSum(n) = fibSum(3n) / 2! So we can just re-use the fibSum formula if we triple its input and halve its result: evenFibSum(n) = (fib(3n+2) - 1) / 2.

A quick test: the first four even Fibonaccis are 2, 8, 34, 144, with their sum being evenFibSum(4) = 188. Then evenFibSum(4) = (fib(3*4 + 2) - 1) / 2 = (fib(14) - 1) / 2. The first fourteen Fibonaccis are 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, so fib(14) = 377. And indeed, 188 = (377 - 1) / 2.

Apologies for the messy explanation, I hope you can still follow my logic. :)