The N-bonacci sequence, originally invented by @DJMcMayhem in this question, is a sequence generated by starting with the integers 0 and 1, and then adding the previous N numbers to generate the next number. The special N-bonacci sequence is an N-bonacci sequence beginning with a pair of numbers other than 0 and 1, which will be named X and Y. If N is greater than the number of terms already in the sequence, simply add all available terms.
So for example the normal fibonacci sequence has an N of 2 (takes the previous two items), and an X and Y of 0 and 1, or 1 and 1, depending on who you ask.
Your Task:
You are to write a program or function that checks whether an inputted integer (A) is part of the special N-bonacci sequence generated by the next three integers (using the second input as N, and the third and fourth as X and Y). Ensure that you handle the special case of N=1.
Input:
Four non-negative integers, A, N, X, and Y.
Output:
A truthy/falsy value that indicates whether A is part of the N-bonacci sequence generated by the N, X, and Y inputs.
Test Cases:
Input: Output:
13,2,0,1->truthy
12,3,1,4->falsy
4,5,0,1-->truthy
8,1,8,9-->truthy
9,1,8,9-->truthy
12,5,0,1->falsy [0,1]>[0,1,1]>[0,1,1,2]>[0,1,1,2,4]>[0,1,1,2,4,8]>[0,1,1,2,4,8,16]>etc.
Scoring:
This is code-golf, so the lowest score in bytes wins.
N==1
is such a weird case. \$\endgroup\$ – Magic Octopus Urn Jun 16 '17 at 14:43N=1
, you might want to call it out in the question, since many answers (including all current answers, I think) will have a failure condition that assumes a strictly increasing series. Also, canX
andY
be negative? That will probably also invalidate all existing answers. \$\endgroup\$ – apsillers Jun 16 '17 at 19:438,1,8,9
and9,1,8,9
to ensure thatN=1
case handling detects the non-repeatedX
value as well as theY
value. (If you want to handle0,0
cases you should add that as well.) \$\endgroup\$ – apsillers Jun 16 '17 at 23:19