A friend of mine told me privately: "I don't like palindromes". "why not?" - I replied. "Because when I want to do some programming challenges, I encounter 2 or 3 ones first related with palindromes. I'm fed up" - he confess me with anger. I said to myself:"Thankfully, that doesn't happen in Codewars".
Talking seriously, we have to count the palindrome integers. Doing that, perhaps, it will help us to make all the flood of palindrome programming challenges more understandable.
For example all the integers of 1 digit (not including 0) are palindromes, 9 cases.
We have nine of them with two digits, so the total amount of palidromes below ```100``` (10^(2)) is ```18```.
At least, will we be able to calculate the amount of them for a certain number of digits?
Let's say for ```2000``` digits?
Prepare a code that given the number of digits ```n```, may output the amount of palindromes of length equals to n and the total amount of palindromes below 10^(n).
You will see more examples in the box.
Happy coding!!
(You don't know what palindromes are? Investigate, :))
from functools import lru_cache

@lru_cache(maxsize=None)
def count_pal(n):
    if n == 0: return [0, 0]
    current = 9 * 10**(n-1>>1)
    previous = count_pal(n-1)[1]
    return [current, current+previous]
from functools import lru_cache

@lru_cache(maxsize=None)
def count_pal(n):
    if n == 0: return [0, 0]
    current = 9 * 10**(n-1>>1)
    previous = count_pal(n-1)[1]
    return [current, current+previous]