Evaluate binomial coefficients: Difference between revisions
→{{header|Perl 6}}: alternate form proposal
(Racket version) |
(→{{header|Perl 6}}: alternate form proposal) |
||
Line 923:
This particular piece of code implements the factorial function as a custom operator, which allows you to use it as you would in mathematical equations. The multi keyword on line 1 is to allow operator overloading.
An alternative is to store the results in a lazy list constant:
<lang Perl6>constant BINOMIAL := gather for 0 .. * -> $n {
take [ map { ([*] $n - $^k + 1 .. $n) / [*] 1 .. $k }, ^$n ]
}
say BINOMIAL[5][3];</lang>
=={{header|PL/I}}==
|