Project Euler Problem 053
Statement
There are exactly ten ways of selecting three from five, 12345:
123, 124, 125, 134, 135, 145, 234, 235, 245, and 345
In combinatorics, we use the notation, $^5C_3 = 10$.
In general,
$^nC_r = \frac{n!}{r!(nr)!}$ ,where r n, n! = n * (n1)…3 * 2 * 1, and 0! = 1 .
It is not until n = 23, that a value exceeds one-million: $^{23}C_{10} = 1144066$.
How many, not necessarily distinct, values of $^nC_r$, for 1 n 100, are greater than one-million?
Solution
Bruteforce approach.
from CommonFunctions import factorial if __name__ == '__main__': result = sum(1 for n in range(1, 101) for r in range(1, n+1) if factorial(n) // factorial(r) // factorial(n-r) > 1000000) print("The result is:", result)
The Python file is available for download here.