Print the N-bonacci sequence
Boolfuck, 6 bytes
,,[;+]
You can safely assume no N-Bonacci numbers will exceed the default number type in your language.
The default number type in Boolfuck is a bit. Assuming this also extends to the input numbers N and X, and given that N>0, there are only two possible inputs - 10 (which outputs nothing) and 11 (which outputs 1).
,
reads a bit into the current memory location. N is ignored as it must be 1. If X is 0, the loop body (surrounded by []
) is skipped. If X is 1, it is output and then flipped to 0 so the loop does not repeat.
Python 2, 79 bytes
n,x=input()
i,f=0,[]
while i<x:v=[sum(f[i-n:]),1][i<n];f.append(v);print v;i+=1
Try it online
Pyth, 13
<Qu+Gs>QGEm1Q
Test Suite
Takes input newline separated, with n
first.
Explanation:
<Qu+Gs>QGEm1Q ## implicit: Q = eval(input)
u Em1Q ## read a line of input, and reduce that many times starting with
## Q 1s in a list, with a lambda G,H
## where G is the old value and H is the new one
+G ## append to the old value
s>QG ## the sum of the last Q values of the old value
<Q ## discard the last Q values of this list