Skip to content

Instantly share code, notes, and snippets.

@izanbf1803
Last active August 26, 2019 17:02
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 izanbf1803/bb43bfa81a89094499b2141cf6484291 to your computer and use it in GitHub Desktop.
Save izanbf1803/bb43bfa81a89094499b2141cf6484291 to your computer and use it in GitHub Desktop.
Combinations formula fast implementation
def nCr(n, r):
if r > n // 2:
return nCr(n, n - r)
prod = 1
for i in range(1, r + 1):
prod *= (n - i + 1) / i
return int(prod)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment