I liked a lot your versions , now it's time for me to write my own in Perl6 , so here it goes:
sub bc($n,$k){[*]map ->$x, $y{$x/$y},(($k+1..$n)Z(1..$n-$k));} (this version is described)I beat the initial one(the "__" one) by 2 characters (mine is 62 characters). It's still compact code but more readable in the sense that one can identify that you're first zipping together two arrays namely the intervals $k+1 -> $n and 1 -> $n-$k which happens if you simplify the k! with the denumerator in the definition of the combinations , after that we're iterating on both intervals at the same time and we're making fractions with their elements , and after that we reduce the fractions by multiplying all of them together using this reduce meta-operator. I find that Perl6 leads to natural code.
Thanks go to moritz_,TimToady,Limbic-Region,jnthn on #perl6 , irc.freenode.net :)
In reply to Re: binomial coefficient
by spx2
in thread binomial coefficient
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |