Last active
August 26, 2019 17:02
-
-
Save izanbf1803/bb43bfa81a89094499b2141cf6484291 to your computer and use it in GitHub Desktop.
Combinations formula fast implementation
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
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