project-euler/158_strings.py

19 lines
400 B
Python
Raw Normal View History

2023-03-25 17:24:17 +01:00
#!/usr/bin/env python3
from math import factorial
def bin(n, k):
if k > n:
return 0
return factorial(n) // (factorial(n-k)*factorial(k))
def strings(k):
k -= 2
s = 0
for inter in range(25):
for i in range(0,k+1):
s += (25-inter) * 2**i * bin(inter, i) * bin(24-inter, k-i)
return s
print(max((2**k - k - 1) * bin(26, k) for k in range(2, 27)))