Skip to content

Instantly share code, notes, and snippets.

@Techcable
Created August 4, 2017 17:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Techcable/3bf553aec848d47f0b722c875e4d052b to your computer and use it in GitHub Desktop.
Save Techcable/3bf553aec848d47f0b722c875e4d052b to your computer and use it in GitHub Desktop.
Euler #53 Combinatoric selections
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