Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Challenges

Comments on Give the fool's fibonacci sequence

Post

Give the fool's fibonacci sequence

+2
−1

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.

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.
Why should this post be closed?

1 comment thread

I don't understand your code nor formula (1 comment)
I don't understand your code nor formula
H_H‭ wrote over 1 year ago · edited over 1 year ago

Possible that i am just stupid. But if you ask me, your challenge requirements are hard to understand.

How does the summation at the end (Part with the Σ) work? From what value do you count till which value and what is your index? And what is the value of f? I know there is f(0) and f(1) .... but i have no idea what f alone means (It would be a function pointer in many languages, but i guess that this isn't the case here).

I have even more trouble understanding what your code does. Can you provide an example in a more normal language? A language that isn't purely functional but more procedural/imperative, like Python, C, C++ or Java or something like that? And please use comments to explain the code and use more descriptive variable and function names.