1
0
Fork 0
mirror of synced 2025-09-23 04:08:33 +00:00
ZoKrates/zokrates_cli/examples/n_choose_k.zok
2022-08-19 17:23:49 +02:00

16 lines
401 B
Text

import "utils/casts/u32_to_field" as to_field;
// Binomial Coeffizient, n!/(k!*(n-k)!).
def fac(field x) -> field {
field mut f = 1;
field mut counter = 0;
for u32 i in 1..100 {
f = counter == x ? f : f * to_field(i);
counter = counter == x ? counter : counter + 1;
}
return f;
}
def main(field n, field k) -> field {
return fac(n) / (fac(k) * fac(n - k));
}