mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-30 16:31:08 +00:00
20 lines
319 B
Python
20 lines
319 B
Python
|
from math import factorial
|
||
|
|
||
|
|
||
|
def combinations(n, k):
|
||
|
"""
|
||
|
>>> combinations(10,5)
|
||
|
252
|
||
|
>>> combinations(6,3)
|
||
|
20
|
||
|
>>> combinations(20,5)
|
||
|
15504
|
||
|
"""
|
||
|
return int(factorial(n) / ((factorial(k)) * (factorial(n - k))))
|
||
|
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
from doctest import testmod
|
||
|
|
||
|
testmod()
|