← Back to challenges

iccanobiF Numbers

PythonHardmathloopsnumbers

Instructions

The Fibonacci sequence, as you know, is generated by iterative addition of the sum of the last two elements of the sequence to the end of the sequence, starting with [0, 1].

Fibonacci = [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, …]

The iccanobiF sequence is generated in a similar way — except that the digits of the last two elements should first be reversed, then added together, then added to the sequence. Single-digit numbers are unaffected, so the first 8 elements are identical to the Fibonacci sequence:

iccanobiF = [0, 1, 1, 2, 3, 5, 8, 13]

The next element is the sum of the reverse of 8 (still 8), and the reverse of 13 — 31 (8 + 31 = 39).

iccanobiF = [0, 1, 1, 2, 3, 5, 8, 13, 39]

The next element is 31 + 93 = 124

iccanobiF = [0, 1, 1, 2, 3, 5, 8, 13, 39, 124]

And so on.

Create a function that takes a number n and returns the difference between the nth iccanobiF number and the nth Fibonacci number.

Examples

icc_minus_fib(4) ➞ 0
# For all n < 9, the difference is zero.

icc_minus_fib(9) ➞ 18

icc_minus_fib(18) ➞ 790920

Notes

N/A

python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.