3 ms·
The only way i know how to work through these types of problems is: - draw a complete probability tree - sum the prob. of all branches that are possible given
by rho4 3y ago
The only way i know how to work through these types of problems is:
- draw a complete probability tree
- sum the prob. of all branches that are possible given the information (having at least 1 boy born on a Tu)
- sum the prob. of all possible branches we're interested in (2 boys)
- divide interesting sum by possible sum
Then assume I made a mistake, invest the same amount of time to program a simple monte carlo simulation to verify the result.
Fix code and probability tree until they match.
Kind of like double book keeping. Very satisfying because you can switch multiple times between theoretical and empirical approach and thinking.
- rho4 3y agoThe 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