1
0
Fork 0
mirror of synced 2025-09-23 12:18:44 +00:00
ZoKrates/examples/n_choose_k.code
2017-10-11 17:41:44 +02:00

16 lines
372 B
Text

// Binomial Coeffizient, n!/(k!*(n-k)!).
def fac(x):
f = 1
counter = 0
for i in 1..100 do
f = if counter == x then f else f * i fi
counter = if counter == x then counter else counter + 1 fi
endfor
return f
def main(n, k):
top = fac(n)
bot1 = fac(k)
sub = n - k
bot2 = fac(sub)
bot = bot1 * bot2
return top / bot