Write a program or named function that will output or return the sequence up to the
nth integer in the Iccanobif sequence, documented on OEIS as A014258. Note that only the zeroth element in the sequence (
0) will be printed if
n is zero.
The sequence is generated by starting like the standard Fibonacci sequence, but after adding the two previous numbers, you flip the result and drop any leading zeros. An interesting fact, to me at least, is that this sequence is not strictly increasing (see the list below). It also seems to be (and probably is) strictly greater than or equal to the Fibonacci sequence.
Your program's input must be an integer.
The first 20 numbers of the sequence are provided here for your viewing pleasure:
0, 1, 1, 2, 3, 5, 8, 31, 93, 421, 415, 638, 3501, 9314, 51821, 53116, 739401, 715297, 8964541, 8389769
Standard loopholes are forbidden.
Shortest program wins.
EDIT: Added a note to clarify that the sequence starts with the zeroth element and should be included if
n is zero.
Example IO possibilities:
0 -> 0 1 -> 0 1 6 -> 0 1 1 2 3 5 8 17 -> [0, 1, 1, 2, 3, 5, 8, 31, 93, 421, 415, 638, 3501, 9314, 51821, 53116, 739401, 715297]
Now that there are several answers, below are my implementations in Python 2 that I worked hard to hide with markup:
#Closest to my initial program. 73 bytes. It should also be noted that this program cannot reach a stack overflow. It runs for n=5000 in less than 10 seconds.
i,a,b=input(),0,1 print a while i:print b;i,a,b=i-1,b,int(str(a+b)[::-1])
#Note that this prints
ntrailing newlines. 64 bytes. Will hit a stack overflow error for large values of n.
def f(n,i=0,j=1):print i,n and f(n-1,j,int(str(i+j)[::-1]))or'';