project-euler/164_numbers_consecutive_dig...

13 lines
274 B
Python
Raw Normal View History

2023-03-25 17:24:17 +01:00
#!/usr/bin/env python3
cache = [[{0 : 1} for b in range(10)] for a in range(10)]
def f(i, a=0, b=0, fst=1):
if i in cache[a][b]:
return cache[a][b][i]
r = sum((f(i-1, b, n, 0) for n in range(fst, 10-a-b)))
cache[a][b][i] = r
return r
print(f(20))