Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,25 @@
|
|||
from typing import (Callable, List, Any)
|
||||
from functools import reduce
|
||||
from operator import mul
|
||||
|
||||
|
||||
def binomialCoefficient(n: int) -> Callable[[int], int]:
|
||||
return lambda k: product(enumFromTo(1 + k)(n)) // factorial(n - k)
|
||||
|
||||
|
||||
def enumFromTo(m: int) -> Callable[[int], List[Any]]:
|
||||
return lambda n: list(range(m, 1 + n))
|
||||
|
||||
|
||||
def factorial(x: int) -> int:
|
||||
return product(enumFromTo(1)(x))
|
||||
|
||||
|
||||
def product(xs: List[Any]) -> int:
|
||||
return reduce(mul, xs, 1)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
print(binomialCoefficient(5)(3))
|
||||
# k=0 to k=5, where n=5
|
||||
print(list(map(binomialCoefficient(5), enumFromTo(0)(5))))
|
||||
Loading…
Add table
Add a link
Reference in a new issue