Skip to content

Instantly share code, notes, and snippets.

@volf52
Last active September 1, 2017 12:30
Show Gist options
  • Save volf52/4f638e29344a910f3a728e27b0f20086 to your computer and use it in GitHub Desktop.
Save volf52/4f638e29344a910f3a728e27b0f20086 to your computer and use it in GitHub Desktop.
Combination nCr in Python
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