Solution to problem 53

This commit is contained in:
David Doblas Jiménez 2021-09-26 17:35:09 +02:00
parent a91d499adc
commit 609badc011

44
src/Python/Problem053.py Normal file
View File

@ -0,0 +1,44 @@
#!/usr/bin/env python3
"""
Created on 26 Sep 2021
@author: David Doblas Jiménez
@email: daviddoji@pm.me
Solution for problem 53 of Project Euler
https://projecteuler.net/problem=53
"""
import math
from utils import timeit
@timeit("Problem 53")
def compute():
"""
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, (5 over 3) = 10.
In general, (n over r) = n!/r!*(n-r)!, where r<=n, n!=n*(n-1)*...*2*1, and 0!=1.
It is not until
, that a value exceeds one-million: (23 over 10) = 1144066.
How many, not necessarily distinct, values of (n over r) for 1<=n<=100, are greater than one-million?
"""
ans = 0
for x in range(101):
for y in range(101):
if math.comb(x, y) > 1_000_000:
ans += 1
return ans
if __name__ == "__main__":
print(f"Result for Problem 53: {compute()}")