Skip to content

Instantly share code, notes, and snippets.

@spullara
Created January 11, 2010 17:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spullara/274437 to your computer and use it in GitHub Desktop.
Save spullara/274437 to your computer and use it in GitHub Desktop.
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