Jump to content

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}}==
1,934

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.