Output the Iccanobif Sequence
Python 2, 58 bytes
a=0;b=1
exec"print a;a,b=b,int(str(a+b)[::-1]);"*-~input()
Uses str
to convert rather than backticks because large enough numbers in Python 2 are written with an L at the end. I tried a recursive function, but it turned out longer (61):
f=lambda n,a=0,b=1:-~n*[0]and[a]+f(n-1,b,int(str(a+b)[::-1]))
Pyth, 17 15 14
Pu+Gs_`s>2GQU2
Try it online
Very basic implementation, starts with range(2)
and adds a number of elements equal to the input, then slices off the extras pops off the last element.
Thanks @Jakube for pointing out the >
reversal thingy.
Explanation
Pu+Gs_`s>2GQU2 : Q = eval(input) (implicit)
P : all but the last element
u QU2 : reduce Q times starting with [0, 1]
+G : add to the previous result
s>2G : sum of the last two elements of G
s_` : int(reversed(repr(above value)))
K, 25 23 bytes
{-1_ x{x,.|$+/-2#x}/!2}
A simple modification of one of the examples at No Stinking Loops.
The phrase .|$
casts a number to a string, reverses it and then evaluates it.
Edit:
Sloppy attention to boundary conditions on my part. More correct now:
{-1_ x{x,.|$+/-2#x}/!2}'0 1 6 10
(,0
0 1
0 1 1 2 3 5 8
0 1 1 2 3 5 8 31 93 421 415)
Edit 2:
(x+1)#
can be replaced with -1_
, saving 2 characters. The space is necessary because otherwise _x
would be an identifier, when I want the "drop" operator applied to a variable called x
.