© Ron Dai 2019
R. DaiLearn Java with Mathhttps://doi.org/10.1007/978-1-4842-5209-3_15

15. Wright Brothers’ Coin Flip Game

Ron Dai1 
(1)
Seattle, WA, USA
 
Programming helps us to understand and explain many complicated problems. You can find an interesting online video, “The coin flip conundrum,” which tells a historic story and explains a probability problem solution using an analytic approach. The story is about the Wright brothers, Orville and Wilbur, who played a coin flip game to determine who should start the new flight experimentation first. They flipped a coin continuously, until Orville got double heads consecutively, or Wilbur received a head and a tail in a “neighboring” sequence. While the video used probability plus algebraic concepts to calculate the winning edge for the Wright brothers, we are going to try the experimentation with Java programming. The following method simulates the Wright brothers’ game and analyzes their results (note the helpful comments, marked by //, so we can read the code more easily).
private static int count_a, count_b, count_ab = 0;
private static int totalsteps_a, totalsteps_b = 0;
/// whoever gets below pattern first wins, or tie if both of them reach targeted patterns at the same round
/// a: HH wins; b: HT wins; Use boolean 'true': head, 'false': tail
public static void flipCoin()
{
       Random r = new Random();
       /// initial value, or first round result
       boolean current_a = r.nextBoolean();
       boolean current_b = r.nextBoolean();
       boolean win_a = false;
       boolean win_b = false;
       int round = 1;
       while(true) {
              round++;
              boolean next_a = r.nextBoolean();
              boolean next_b = r.nextBoolean();
              if (current_a && next_a) {
                     win_a = true;
              }
              if (current_b && !next_b) {
                     win_b = true;
              }
              if (win_a && win_b) {
                     System.out.println("Both WIN! - round: " + round);
                     count_ab++;
                     totalsteps_a += round;
                     totalsteps_b += round;
                     break;
              }
              if (win_a && !win_b) {
                     System.out.println("A WIN! - round: " + round);
                     count_a++;
                     totalsteps_a += round;
                     break;
              }
              if (!win_a && win_b) {
                     System.out.println("B WIN! - round: " + round);
                     count_b++;
                     totalsteps_b += round;
                     break;
              }
              current_a = next_a;
              current_b = next_b;
       }
}
Using the following main method, we can collect samples and get the statistical summary.
public static void main(String[] args) {
       final int MAX = 10000;
       for(int i=0; i < MAX; i++) {
              flipCoin();
       }
       System.out.println("Summary");
       System.out.println("Total samples: " + MAX);
       System.out.println("Winning counts: a - " + count_a + "; b - " + count_b + "; ab - " + count_ab);
       int probability_a = count_a * 100 / (count_a + count_b);
       int probability_b = count_b * 100 / (count_a + count_b);
       System.out.println("Winning probability: HH=" + probability_a + "%; HT=" + probability_b + "%.");
       double average_a = totalsteps_a / (count_a + count_ab);
       double average_b = totalsteps_b / (count_b + count_ab);
       System.out.println("Average rounds to win: HH=" + average_a + "; HT=" + average_b + ".");
}
After we run many experiments with different parameters, we learn what is actually going on and can then reach the conclusion that Wilbur would have a significantly higher chance (roughly 62% vs. 37%) to win the bet. The output should look similar to what follows.
.........
B WIN! - round: 3
A WIN! - round: 2
A WIN! - round: 3
B WIN! - round: 2
B WIN! - round: 4
A WIN! - round: 4
B WIN! - round: 2
B WIN! - round: 2
B WIN! - round: 3
B WIN! - round: 2
A WIN! - round: 2
A WIN! - round: 2
Both WIN! - round: 2
B WIN! - round: 3
Summary
Total samples: 10000
Winning counts: a - 3213; b - 5386; ab - 1401
Winning probability: HH=37%; HT=62%.
Average rounds to win: HH=2.0; HT=3.0.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.17.174.239