Solve problem 162.

This commit is contained in:
2024-06-11 02:11:32 -04:00
parent 8fdec345d9
commit 1159fe0747

39
python/e162.py Normal file
View File

@@ -0,0 +1,39 @@
from functools import lru_cache
@lru_cache
def combs(xs, first=False):
if xs == (0, 0, 0, 0):
return 1
c = 0
z, o, a, r = xs
if (not first) and z > 0:
c += combs((z - 1, o, a, r))
if o > 0:
c += combs((z, o - 1, a, r))
if a > 0:
c += combs((z, o, a - 1, r))
if r > 0:
c += 13 * combs((z, o, a, r - 1))
return c
def euler_162():
t = 0
for n in range(17):
for z in range(1, n + 1):
for o in range(1, n + 1):
for a in range(1, n + 1):
r = n - z - o - a
if not r >= 0:
continue
t += combs((z, o, a, r), True)
return hex(t)[2:].upper()
if __name__ == "__main__":
solution = euler_162()
print("e162.py: " + str(solution))
assert(solution == "3D58725572C62302")