Skip to content

Instantly share code, notes, and snippets.

@carlos-adir
Created December 12, 2023 13:17
Show Gist options
  • Save carlos-adir/c1128c8c1bb29cdb10e421cb8e367524 to your computer and use it in GitHub Desktop.
Save carlos-adir/c1128c8c1bb29cdb10e421cb8e367524 to your computer and use it in GitHub Desktop.
Light binomial coefficient
def comb(a: int, b: int) -> int:
"""
Implements the binomial coefficient:
( a ) a !
( ) = -------------
( b ) b! * (a-b)!
"""
prod = 1
for i in range(min(b, a-b)):
prod *= a-i
prod /= i+1
return prod
@carlos-adir
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment