32 lines
672 B
Python
32 lines
672 B
Python
from lib import get_data
|
|
from lib import ints
|
|
|
|
data = get_data(__file__)
|
|
xs = ints(data)
|
|
CACHE = {}
|
|
|
|
# I had maxsize too small at first :/
|
|
# @lru_cache(maxsize=10**12)
|
|
def apply(x, rest):
|
|
if rest == 0:
|
|
return 1
|
|
|
|
if (x, rest) in CACHE:
|
|
return CACHE[(x, rest)]
|
|
|
|
if x == 0:
|
|
r = apply(1, rest - 1)
|
|
elif len(str(x)) % 2 == 0:
|
|
sx = str(x)
|
|
a = int(sx[: len(sx) // 2])
|
|
b = int(sx[len(sx) // 2 :])
|
|
r = apply(a, rest - 1) + apply(b, rest - 1)
|
|
else:
|
|
r = apply(x * 2024, rest - 1)
|
|
CACHE[(x, rest)] = r
|
|
return r
|
|
|
|
|
|
print(sum([apply(x, 25) for x in xs]))
|
|
print(sum([apply(x, 75) for x in xs]))
|