05-28-2015, 03:08 PM

Dieter and I had been discussing improving this algorithm here, and I realized it would be easy to implement on the 17BII solver with definite loops and iterative computation/summation. So here we are. Line breaks and C-like comments added for legibility.

Example:

Find the probability of rolling a six at least 40 times when rolling a standard six-sided die 120 times.

120 N

6 1/x P1

40 L

120 H

PΣ

Result:

6.41962987692E-6, or .000642% (i.e. don't wager any money on that bet)

Example:

Find the probability of rolling a six at least 40 times when rolling a standard six-sided die 120 times.

120 N

6 1/x P1

40 L

120 H

PΣ

Result:

6.41962987692E-6, or .000642% (i.e. don't wager any money on that bet)

Code:

`BINPROB:`

0*(N+P1+L+H) //Set up menu variable ordering

+0*L(B:N) //Initialize B

+0*Σ(X:2:L:1: //Iteratively compute B=nCr(N,L)

L(B:G(B)/X*(N-X+1))

)

+0*L(PΣ:L(B:G(B)*P1^L*(1-P1)^(N-L))) //Initialize PΣ with BinProb(N,L,P)

+0*Σ(X:L:H-1:1: //Iteratively compute sum of BinProb(N,L..H,P)

L(PΣ:PΣ+L(B:G(B)/(X+1)*(N-X)*P1/(1-P1)))

)

+PΣ=PΣ //Spit out result