3 ms·
The simulation code: public class Test { public static enum Outcome { B_Mo, B_Tu, B_We, B_Th, B_Fr, B_Sa, B_Su, G_Mo, G_Tu, G_We, G_Th, G_Fr, G_S
by rho4 3y ago
The simulation code:
public class Test {
public static enum Outcome {
B_Mo, B_Tu, B_We, B_Th, B_Fr, B_Sa, B_Su, G_Mo, G_Tu, G_We, G_Th, G_Fr, G_Sa, G_Su;
boolean isBoy() {
return this == B_Mo || this == B_Tu || this == B_We || this == B_Th || this == B_Fr || this == B_Sa || this == B_Su;
}
}
public static void main(String[] args) {
Random r = new Random();
int count_experiments = 1_000_000_000;
double count_possible_given_info = 0;
double count_interesting = 0;
System.out.println("theoretical (13/27): " + (13.0 / 27.0));
for(int i = 0; i < count_experiments; i++) {
Outcome child_1 = Outcome.values()[r.nextInt(Outcome.values().length)];
Outcome child_2 = Outcome.values()[r.nextInt(Outcome.values().length)];
boolean possible_given_info = child_1 == Outcome.B_Tu || child_2 == Outcome.B_Tu;
boolean interesting = possible_given_info && child_1.isBoy() && child_2.isBoy();
count_possible_given_info += possible_given_info ? 1 : 0;
count_interesting += interesting ? 1 : 0;
}
System.out.println("count_experiments: " + count_experiments);
System.out.println("count_possible_given_info: " + count_possible_given_info);
System.out.println("count_interesting: " + count_interesting);
System.out.println("count_interesting / count_possible_given_info: " + (count_interesting / count_possible_given_info));
}
}
Example output:
theoretical (13/27): 0.48148148148148145
count_experiments: 1000000000
count_possible_given_info: 1.3775374E8
count_interesting: 6.632153E7
count_interesting / count_possible_given_info: 0.481449941032454