import java.util.Random;

public class Flipper {
  public static void main( String args[] ) {
    final int GOAL = 5;
    final int TRIALS = 1000000;
    final int FLIPS = 100;
    Random r = new Random();
    
    int successCount = 0;
    for (int trial=0; trial<TRIALS; trial++) {
      // generate some throws
      boolean flips[] = new boolean[FLIPS];
      for (int flip=0; flip<flips.length; flip++) {
        flips[flip] = r.nextBoolean();
      }
      // any five in a row the same?
      boolean success = false;
      int count = 1;
      boolean current = flips[0];
      for (int flip=1; flip<flips.length; flip++) {
        if (current == flips[flip]) {
          count++;
          if (count == GOAL) {
            success = true;
            break;
          }
        } else {
          count = 1;
          current = flips[flip];
        }
      }
      if (success) successCount++;
    }
    System.out.println("success prob = "+((float)successCount)/TRIALS);
  }
}
