Created
April 29, 2011 12:07
-
-
Save chenshuo/948216 to your computer and use it in GitHub Desktop.
prob of 10 in a row, picking 60 out of 228.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Main { | |
public final static int kHoles = 228; | |
public final static int kBalls = 60; | |
public static void main(String[] args) { | |
Random r = new Random(); | |
int[] hist = new int[kBalls + 1]; | |
for (int round = 0; round < 1000*1000*10; ++round) { | |
boolean[] holes = new boolean[kHoles+1]; | |
int balls = 0; | |
while (balls < kBalls) { | |
int x = r.nextInt(kHoles); | |
if (!holes[x]) { | |
holes[x] = true; | |
++balls; | |
} | |
} | |
int maxContinues = 0; | |
int continues = 0; | |
for (int i = 0; i < holes.length; ++i) { | |
if (holes[i]) { | |
++continues; | |
} | |
else { | |
if (continues > maxContinues) | |
maxContinues = continues; | |
continues = 0; | |
} | |
} | |
++hist[maxContinues]; | |
} | |
for (int i = 0; i < hist.length; ++i) { | |
System.out.printf("%2d %d\n", i, hist[i]); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment