Skip to content

Instantly share code, notes, and snippets.

@MachineCharmer
MachineCharmer / cnk.py
Created March 10, 2011 12:49 — forked from ikbear/cnk.py
function to calculate number of combinations
import operator
def c(n, k):
k = min(k,n-k) # using C(n,k) = C(n,n-k)
return (reduce(operator.mul, range(n-k+1, n+1)) /
reduce(operator.mul, range(1, k+1)))