Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.66 KB | None | 0 0
  1.  
  2. public class ScrabbleBet {
  3.     public static void main(String[] arfs) {
  4.         ScrabbleBet s = new ScrabbleBet();
  5.         System.out.println(s.estimate(2,2,1,50));;
  6.         System.out.println(s.estimate(10,10,5,25));
  7.     }
  8.     public double estimate(int trials, int games, int winsNeeded, int winChance) {
  9.         double wc = (double)winsNeeded / 100.0;
  10.         double prob = 0;
  11.         for (int k = 0; k < winsNeeded; k++) {
  12.             prob += Math.pow(wc, k) * Math.pow(1 - wc, games - k) * (fact(games)/(fact(k) * fact(games - k)));
  13.         }
  14.         return Math.pow(prob, trials);
  15.     }
  16.    
  17.     private static long fact(int in) {
  18.         long ans = 1;
  19.         for (int x = 1; x <= in; x++) {
  20.             ans *= in;
  21.         }
  22.         return ans;
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement