Evaluate binomial coefficients: Difference between revisions
→{{header|dc}}
(→{{header|dc}}: Add commented version.) |
|||
Line 367:
<lang dc>[ macro z: factorial base case when n is (z)ero ]sx
[sx [ x is our dump register;
1 [ return value is 1 ]sx
q] [ abort processing of calling macro ]sx
Line 373:
[ macro f: factorial ]sx [
d [ duplicate the input (n) ]sx
0 =z [ if
d [ otherwise, duplicate n again ]sx
1 - [ subtract 1 ]sx
Line 381:
] sf
[ macro b(n,k): binomial function (n choose k)
straightforward RPN version of formula.]sx [
/ [ divide: n!/(n-k)!k! ]sx
] sb
|