Evaluate binomial coefficients: Difference between revisions
Content added Content deleted
(→{{header|Perl 6}}: div can actually be used here to solve the type issue) |
|||
Line 1,333: | Line 1,333: | ||
=={{header|Perl 6}}== |
=={{header|Perl 6}}== |
||
<lang perl6>sub infix:<choose> { [*] ($^n ... 0) |
<lang perl6>sub infix:<choose> { [*] ($^n ... 0) Z/ 1 .. $^p } |
||
say 5 choose 3;</lang> |
say 5 choose 3;</lang> |
||
{{out}} |
{{out}} |
||
<pre>10</pre> |
<pre>10</pre> |
||
One drawback of this method is that it returns a Rat, not an Int. If we really worry about it, we can enforce the conversion: |
|||
<lang perl6>sub infix:<choose> { ([*] ($^n ... 0) Z/ 1 .. $^p).Int }</lang> |
|||
=={{header|PL/I}}== |
=={{header|PL/I}}== |