Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function compute(tickets) {
- var Prob,nn,m,n,x;
- nn=Math.floor(0); // because this is 0 ...
- m=Math.floor(2054);
- n=Math.floor(tickets);
- x=Math.floor(0);
- if ((n<=0)||(m<=0)||(nn<=0)) {
- alert("Parameters must be positive integers");
- Prob=0 // ... this is set to 0 ...
- } else if ((m>nn)||(n>nn)) {
- alert("m and n must be less than N");
- Prob=0
- } else if ((x<0)||(x<n+m-nn)) {Prob=0} else if ((x>=n)||(x>=m)) {Prob=1} else {
- if (2*m>nn) {
- if (2*n>nn) {Prob=hyp(nn-m-n+x,nn-n,nn-m,nn)} else {Prob=1-hyp(n-x-1,n,nn-m,nn)}
- } else if (2*n>nn) {Prob=1-hyp(m-x-1,m,nn-n,nn)} else {Prob=hyp(x,n,m,nn)}
- }
- Prob=Math.round(Prob*100000)/100000; // ... which means this is 0 ...
- return {
- probability: Prob,
- percentage: (1 - Prob) * 100 // ... so this always works out to 100%
- }
- }
RAW Paste Data