Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,10 @@
|
|||
def factorial = { x ->
|
||||
assert x > -1
|
||||
x == 0 ? 1 : (1..x).inject(1G) { BigInteger product, BigInteger factor -> product *= factor }
|
||||
}
|
||||
|
||||
def combinations = { n, k ->
|
||||
assert k >= 0
|
||||
assert n >= k
|
||||
factorial(n).intdiv(factorial(k)*factorial(n-k))
|
||||
}
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
assert combinations(20, 0) == combinations(20, 20)
|
||||
assert combinations(20, 10) == (combinations(19, 9) + combinations(19, 10))
|
||||
assert combinations(5, 3) == 10
|
||||
println combinations(5, 3)
|
||||
Loading…
Add table
Add a link
Reference in a new issue