Created
August 4, 2017 17:34
-
-
Save Techcable/3bf553aec848d47f0b722c875e4d052b to your computer and use it in GitHub Desktop.
Euler #53 Combinatoric selections
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from math import factorial | |
def numCombinations(n, r): | |
return factorial(n) // (factorial(r) * factorial(n - r)) | |
def numCombinationsBiggerThan(n, target): | |
amount = 0 | |
for r in range(1, n + 1): | |
if numCombinations(n, r) > target: | |
amount += 1 | |
return amount | |
target = 10**6 | |
result = sum( | |
numCombinationsBiggerThan(n, target) for n in range(1, 101) | |
) | |
print(f"Total combinations bigger than a million for n <= 100: {result}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment