mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-07-06 10:31:29 +08:00
Added to maths and strings (#1642)
* Added to maths and strings * added changes suggest by cclauss
This commit is contained in:

committed by
Christian Clauss

parent
e849578e59
commit
a26ae00b24
19
maths/combinations.py
Normal file
19
maths/combinations.py
Normal file
@ -0,0 +1,19 @@
|
||||
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()
|
Reference in New Issue
Block a user