Last active
September 1, 2017 12:30
-
-
Save volf52/4f638e29344a910f3a728e27b0f20086 to your computer and use it in GitHub Desktop.
Combination nCr in Python
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
import operator as op | |
def ncr(n, x): | |
x = min(n, n-x) | |
if x == 0: return 1 | |
num = reduce(op.mul, xrange(n, n-x, -1)) | |
denom = reduce(op.mul, xrange(1, x+1)) | |
return num // denom |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment