in reply to binomial coefficient

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)
sub bc($n,$k){[*]map ->$x, $y{$x/$y},(($n-$k+1..$n)Z(1..$k));} (the same thing,if you simplify (n-k)! instead of k!)

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 :)

Replies are listed 'Best First'.
Re^2: binomial coefficient
by eklerks (Novice) on Jul 14, 2009 at 09:09 UTC
    I decided to register myself. Better late than never. About your code, it is beautiful! It is very natural indeed. I should take an in depth look into perl6 very soon.