Skip to content

Instantly share code, notes, and snippets.

@yeiichi
Created May 29, 2020 00:05
Show Gist options
  • Save yeiichi/9ffc98e2a47544994a2a8e581d8f9acc to your computer and use it in GitHub Desktop.
Save yeiichi/9ffc98e2a47544994a2a8e581d8f9acc to your computer and use it in GitHub Desktop.
Calculates a combination C(n, r)
# https://stackoverflow.com/questions/4941753/
import math
def ncr(n, r):
'''Returns a combination C(n, r)'''
f = math.factorial
return int(f(n) / f(n-r) / f(r))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment