22
2
Write a program or named function that will output or return the sequence up to the n
th 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:
Iterative:
#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])
Recursive:
#Note that this printsn
trailing 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'';
8+1 for thinking of something to do with the Fibonacci sequence that hasn´t been done before – Level River St – 2015-06-23T21:38:55.690
@steveverrill I decided I wanted to make another challenge, then started with just deciding to see what the sequence would look like, after I imagined it. So I wrote a program. Then I searched OEIS and made the challenge. – mbomb007 – 2015-06-23T21:42:55.167
Was it inspired by this question?
– JohnE – 2015-06-23T23:58:20.733@JohnE No. I've seen it before, but that challenge is one of the most simple challenges on this site. No, I was just creating a number sequence purely from my imagination that I could use as a challenge. – mbomb007 – 2015-06-24T01:15:54.483
3I think you should wait a little longer before accepting an answer. Unless one of the answers is clearly unbeatable (e.g., a 1 byte solution), it's advisable to wait at least a week. – Dennis – 2015-06-24T06:13:29.073
@Dennis I was going to update which answer is accepted if it gets beaten, but I'll un-accept it. You'll probably have to remind me to accept an answer, unless PCG sends reminders. – mbomb007 – 2015-06-24T15:48:43.013
@mbomb007 I usually accept an answer after a day or so, and update it when it's beaten. It's not a big deal either way. – undergroundmonorail – 2015-06-25T05:59:11.130
@mbomb007 Why do you require a named function? – flawr – 2017-02-02T09:58:11.733
Idk. I wrote it in 2015. I'm not going to change it now. – mbomb007 – 2017-02-02T14:24:32.357