Evaluate binomial coefficients: Difference between revisions
Content added Content deleted
(→{{header|Perl 6}}: alternate form proposal) |
|||
Line 923: | 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. |
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}}== |
=={{header|PL/I}}== |