This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from textwrap import dedent | |
string = """ | |
Only now, | |
I'm starting to see the light. | |
The shadows of doubt, | |
fading into the night. | |
""" | |
print("Original string:") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
from functools import lru_cache | |
@lru_cache(maxsize=None) | |
def fib(n: int) -> int: | |
if n < 2: | |
return n | |
return fib(n - 1) + fib(n - 2) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
This week's question: | |
Given a number n, find the sum of all n-digit palindromes. | |
Example: | |
> nPalindromes(2) | |
> 495 // 11 + 22 + 33 + 44 + 55 + 66 + 77 + 88 + 99 | |
""" |