project-euler/113_non-bouncy_numbers.py

18 lines
361 B
Python

#!/usr/bin/env python3
from math import factorial
def main(k):
n = 10
ascend = binomial(n+k-1, k)
descnd = sum(binomial(n+i-1, i) for i in range(1,k+1))
repeat = n*k + 1 # why 1
return ascend + descnd - repeat
def binomial(n, k):
return factorial(n) // (factorial(k)*factorial(n-k))
#print(main(6))
#print(main(10))
print(main(100))