Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ScrabbleBet {
- public static void main(String[] arfs) {
- ScrabbleBet s = new ScrabbleBet();
- System.out.println(s.estimate(2,2,1,50));;
- System.out.println(s.estimate(10,10,5,25));
- }
- public double estimate(int trials, int games, int winsNeeded, int winChance) {
- double wc = (double)winsNeeded / 100.0;
- double prob = 0;
- for (int k = 0; k < winsNeeded; k++) {
- prob += Math.pow(wc, k) * Math.pow(1 - wc, games - k) * (fact(games)/(fact(k) * fact(games - k)));
- }
- return Math.pow(prob, trials);
- }
- private static long fact(int in) {
- long ans = 1;
- for (int x = 1; x <= in; x++) {
- ans *= in;
- }
- return ans;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement