Skip to main content

Wright Brothers’ Coin Flip Game

  • Chapter
  • First Online:
Learn Java with Math
  • 1407 Accesses

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 to check access.

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 39.99
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 54.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Author information

Authors and Affiliations

Authors

Rights and permissions

Reprints and permissions

Copyright information

© 2019 Ron Dai

About this chapter

Check for updates. Verify currency and authenticity via CrossMark

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

Publish with us

Policies and ethics