Evaluate binomial coefficients: Difference between revisions

(Added Quackery.)
Line 432:
The Windows cmd console only handles 32-bit integers. If a factoral exceeds 2147483647 at any point, <code>set /a</code> will choke and roll over to a negative value, giving unexpected results. Unfortunately, this is as good as it gets for pure batch.
 
=={{header|BCPL}}==
<lang BCPL>
GET "libhdr"
 
LET choose(n, k) =
~(0 <= k <= n) -> 0,
2*k > n -> binomial(n, n - k),
binomial(n, k)
 
AND binomial(n, k) =
k = 0 -> 1,
binomial(n, k - 1) * (n - k + 1) / k
 
LET start() = VALOF {
LET n, k = ?, ?
LET argv = VEC 20
LET sz = ?
 
sz := rdargs("n/a/n/p,k/a/n/p", argv, 20)
UNLESS sz ~= 0 RESULTIS 1
 
n := !argv!0
k := !argv!1
 
writef("%d choose %d = %d *n", n, k, choose(n, k))
RESULTIS 0
}
</lang>
{{Out}}
Note that with the /p flag to rdargs(), the system will prompt if we don't supply both arguments on the command line.
<pre>
$ cintsys64
 
BCPL 64-bit Cintcode System (13 Jan 2020)
0.004> nCk 50 25
50 choose 25 = 126410606437752
0.003> nCk 10 5
10 choose 5 = 252
0.004> nCk 100 2
100 choose 2 = 4950
0.004> nCk
n > 5
k > 3
5 choose 3 = 10
</pre>
=={{header|BBC BASIC}}==
<lang bbcbasic> @%=&1010
357

edits