Created
January 11, 2010 17:58
-
-
Save spullara/274437 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
package com.sampullara.survivor; | |
import java.security.SecureRandom; | |
import java.util.Random; | |
public class Simulator { | |
public static void main(String[] args) { | |
Random r = new SecureRandom(); | |
double[] correct = new double[] { | |
.9525, | |
.7288, | |
.9316, | |
.9817, | |
.9466, | |
.5567, | |
.9617, | |
.8616, | |
.8333, | |
.5647, | |
.9734, | |
.8266, | |
.9163, | |
.6430, | |
.7719, | |
.4723 | |
}; | |
byte[] players = new byte[1000000]; | |
for (double c : correct) { | |
for (int i = 0; i < players.length; i++) { | |
byte misses = players[i]; | |
if (misses == 3) continue; | |
if (r.nextDouble() > c) { | |
players[i]++; | |
} | |
} | |
} | |
int total = 0; | |
for (byte misses : players) { | |
if (misses == 0) total++; | |
} | |
System.out.println(((double)total)/1000000d); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment