Evaluate binomial coefficients: Difference between revisions

add RPL
m (syntax highlighting fixup automation)
(add RPL)
Line 2,457:
return numer
</syntaxhighlight>
 
=={{header|RPL}}==
RPL has a <code>COMB</code> instruction which returns the result directly. If a home-made function is preferred, there many possibilities.
 
Using the recommended formula and the stack:
≪ - LAST ! SWAP ! SWAP ROT ! * / ≫ ‘'''CHOOS'''’ STO
Using the formula with local variables:
≪ → n k ≪ n ! n k - ! / k ! / ≫ ≫ ‘'''CHOOS'''’ STO
To avoid data overflow for high values of n, using the formula simplified by (n-k)! :
≪ → n k ≪ 1 n k - 1 + n '''FOR''' j j * '''NEXT''' k ! / ≫ ≫ ‘'''CHOOS'''’ STO
All the above functions are called the same way and return the same result:
5 3 '''CHOOS'''
{{out}}
<pre>
10
</pre>
 
=={{header|Ruby}}==
1,150

edits