19
3
Background
Most everyone is familiar with the Fibonacci numbers F(n)
:
0, 1, 1, 2, 3, 5, 8, 13, 21 ...
These are formed by the recursion function F(n) = F(n-1) + F(n-2)
with F(0)=0
and F(1)=1
. A000045
A closely related sequence is the Lucas numbers L(m)
:
2, 1, 3, 4, 7, 11, 18, 29 ...
These are formed by the recursion function L(m) = L(m-1) + L(m-2)
with L(0)=2
and L(1)=1
. A000032
We can alternate between the two sequences based on even/odd indices, with the construction
A(x) = F(x)
if x mod 2 = 0
and A(x) = L(x)
otherwise. For example, A(4)
is equal to F(4)
since 4 mod 2 = 0
. We'll call this sequence the Lucas-nacci Numbers, A(x)
:
0, 1, 1, 4, 3, 11, 8, 29, 21, 76 ...
This can be formed by the recursion function A(x) = 3*A(x-2) - A(x-4)
with A(0)=0
, A(1)=1
, A(2)=1
, and A(3)=4
. A005013
Challenge
Given input n
, output the sequence of n+1
numbers up to and including A(n)
as described above. Fewest bytes (or byte-equivalents, such as for LabVIEW, as determined individually on Meta) wins.
Input
A single non-negative integer n
.
Output
A list of numbers that correspond to the subsequence of Lucas-nacci numbers from A(0)
to A(n)
. The list must be in sequential order as described above.
Rules
- Standard code-golf rules and loophole restrictions apply.
- Standard input/output rules apply.
- Input number can be in any suitable format: unary or decimal, read from STDIN, function or command-line argument, etc. - your choice.
- Output can be printed to STDOUT or returned as a result of the function call. If printed, suitable delimiters to differentiate the numbers must be included (space-separated, comma-separated, etc.).
- Additionally, if output to STDOUT, surrounding whitespace, trailing newline, etc. are all optional.
- If the input is a non-integer or a negative integer, the program can do anything or nothing, as behavior is undefined.
Examples
Input -> Output
0 -> 0
5 -> 0, 1, 1, 4, 3, 11
18 -> 0, 1, 1, 4, 3, 11, 8, 29, 21, 76, 55, 199, 144, 521, 377, 1364, 987, 3571, 2584
Is newline considered an accepted delimiter? – corsiKa – 2016-02-08T20:51:55.100
@corsiKa Sure, that's fine. – AdmBorkBork – 2016-02-08T21:26:40.260