Evaluate binomial coefficients: Difference between revisions
Content added Content deleted
m (→{{header|REXX}}: added/changed comments, changed output, added whitespace, added subroutine fences. -- ~~~~) |
|||
Line 1,046: | Line 1,046: | ||
=={{header|REXX}}== |
=={{header|REXX}}== |
||
The task is to compute ANY binomial coefficient(s), but this example is limited to 100k digits. |
The task is to compute ANY binomial coefficient(s), but this example is limited to 100k digits. |
||
<lang rexx>/*REXX program calculates binomial coefficients (aka, combinations). |
<lang rexx>/*REXX program calculates binomial coefficients (aka, combinations). */ |
||
numeric digits 100000 |
numeric digits 100000 |
||
parse arg n k . |
parse arg n k . |
||
say ' |
say 'combinations('n","k') =' comb(n,k) |
||
exit /*stick a fork in it, we're done.*/ |
|||
exit |
|||
/*──────────────────────────────────COMB subroutine─────────────────────*/ |
|||
⚫ | |||
/*──────────────────────────────────FACT subroutine─────────────────────*/ |
|||
⚫ | |||
fact: procedure; parse arg z; !=1; do j=2 to z; !=!*j; end; return !</lang> |
fact: procedure; parse arg z; !=1; do j=2 to z; !=!*j; end; return !</lang> |
||
'''output''' when using the input of: <tt> 5 3 </tt> |
|||
<pre>5 3</pre> |
|||
<pre> |
<pre> |
||
combinations(5,3) = 10 |
|||
</pre> |
</pre> |
||
'''output''' when using the input of: <tt> 1200 120 </tt> |
|||
⚫ | |||
<pre>1200 120</pre> |
|||
⚫ | |||
⚫ | |||
⚫ | |||
</pre> |
</pre> |
||