Comments on Give the fool's fibonacci sequence
Parent
Give the fool's fibonacci sequence
Recently I asked for tips on improving some code-golf of mine. The code was supposed to output every third value of the Fibonacci sequence starting with 2:
2,8,34,144,610,2584,10946,46368,196418,832040
However, I made a mistake in deriving my formula, and my code output a different sequence which is accurate for the first couple terms and then begins to diverge:
2,8,34,140,578,2384,9834,40564,167322,690184
My sequence is defined by:
\begin{array}{rcl} f(0) &=& 0 \\ f(1) &=& 2 \\ f(n) &=&\displaystyle 2 + 3f(n-1) + 4f(n-2) + 2\sum_{0}^{n-3}f\\ \end{array}or in terms of my original Haskell code:
z=zipWith(+)
g=z((*2)<$>0:0:g)$z(0:g)$(*2)<$>scanl(+)1g
Your task is to implement a sequence of integers, which has my incorrect sequence as every third value. The other values can be whatever you want them to be, it simply must have the above sequence as every third value. The sequence can begin at the 0th, 1st, or 2nd index, whichever you please.
This is code-golf so the goal is to minimize the size of your program as measured in bytes.
[Lean 4], 115 109 104 89 bytes …
1y ago
Japt, 23 bytes >0©3ò4Èß …
5mo ago
Python 3, 131 75 62 bytes ` …
1y ago
JavaScript, 40 bytes f= …
5mo ago
Post
Python 3, 131 75 62 bytes
f=lambda n:n>0and 2+3*f(n-1)+4*f(n-2)+2*sum(map(f,range(n-2)))
I know, a one-liner is boring. This is because I apparently didn't need a separate function/lambda to compute the sum of something. So there you have it, a 56 69 (nice) byte save in total. :D

1 comment thread