# Worldbuilders Probability

Dec 8th, 2015
115
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. function compute(tickets) {
2.     var Prob,nn,m,n,x;
3.     nn=Math.floor(0); // because this is 0 ...
4.     m=Math.floor(2054);
5.     n=Math.floor(tickets);
6.     x=Math.floor(0);
7.     if ((n<=0)||(m<=0)||(nn<=0)) {
8.         alert("Parameters must be positive integers");
9.         Prob=0 // ... this is set to 0 ...
10.     } else if ((m>nn)||(n>nn)) {
11.         alert("m and n must be less than N");
12.         Prob=0
13.     } else if ((x<0)||(x<n+m-nn)) {Prob=0} else if ((x>=n)||(x>=m)) {Prob=1} else {
14.         if (2*m>nn) {
15.             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)}
16.         } else if (2*n>nn) {Prob=1-hyp(m-x-1,m,nn-n,nn)} else {Prob=hyp(x,n,m,nn)}
17.     }
18.     Prob=Math.round(Prob*100000)/100000; // ... which means this is 0 ...
19.
20.     return {
21.         probability: Prob,
22.         percentage: (1 - Prob) * 100 // ... so this always works out to 100%
23.     }
24. }
RAW Paste Data