Abstract
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; } }
This is a preview of subscription content, log in via an institution.
Buying options
Tax calculation will be finalised at checkout
Purchases are for personal use only
Learn about institutional subscriptionsAuthor information
Authors and Affiliations
Rights and permissions
Copyright information
© 2019 Ron Dai
About this chapter
Cite this chapter
Dai, R. (2019). Wright Brothers’ Coin Flip Game. In: Learn Java with Math. Apress, Berkeley, CA. https://doi.org/10.1007/978-1-4842-5209-3_15
Download citation
DOI: https://doi.org/10.1007/978-1-4842-5209-3_15
Published:
Publisher Name: Apress, Berkeley, CA
Print ISBN: 978-1-4842-5208-6
Online ISBN: 978-1-4842-5209-3
eBook Packages: Professional and Applied ComputingProfessional and Applied Computing (R0)Apress Access Books