1
0
Fork 0
mirror of synced 2025-09-24 04:40:05 +00:00
ZoKrates/zokrates_cli/tests/code/n_choose_k.zok
2022-06-28 19:23:45 +02:00

16 lines
395 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));
}