/* Daughter or son in Picat. From https://brainstellar.com/puzzles/probability/25 """ Sheldon says "Suppose I have two children. Younger one is a girl". What is the probability that both children are girls? "Forget all that, and suppose I have two children, and atleast one of them is a boy". Find probability of two boys. "Suppose I have two kids, lets call them Bouba and Kiki", says Dr. Cooper, "and suppose Bouba is a girl !" What is the probability that I have two daughters?" """ (Note: The Answer states 1/2, 1/3, 1/3 but in the Solution, the third is stated to be 1/2. See Comments on this.) Cf - ppl_two_children_problem.pi - ppl_how_many_sons.pi - my Gamble model gamble_daughter_or_son.rkt This program was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import ppl_distributions, ppl_utils. import util. main => go. /* """ Sheldon says "Suppose I have two children. Younger one is a girl". What is the probability that both children are girls? """ var : child1 Probabilities: girl: 0.7256972111553784 boy: 0.2743027888446215 mean = [girl = 0.725697,boy = 0.274303] var : child2 Probabilities: girl: 0.7760956175298804 boy: 0.2239043824701195 mean = [girl = 0.776096,boy = 0.223904] var : youngest Probabilities: girl: 1.0000000000000000 mean = [girl = 1.0] var : p Probabilities: true: 0.5017928286852590 false: 0.4982071713147410 mean = [true = 0.501793,false = 0.498207] I.e. the probability that both children are girls (p) is 1/2. */ go ?=> reset_store, run_model(10_000,$model,[show_probs_trunc,mean]), nl, % show_store_lengths,nl, % fail, nl. go => true. model() => N = 2, Gender = [condt(flip(1/2),boy,girl) : _ in 1..N], Age = [ random_integer(10) : _ in 1..N], Child1 = Gender[1], Child2 = Gender[2], Age1 = Age[1], Age2 = Age[2], Youngest = cond(Age1 < Age2,Child1,Child2), P = check((Child1 == girl, Child2 == girl)), observe(Youngest == girl), if observed_ok then add("child1",Child1), add("child2",Child2), add("youngest",Youngest), add("p",P) end. /* """ "Forget all that, and suppose I have two children, and atleast one of them is a boy". Find probability of two boys. """ var : child1 Probabilities: boy: 0.6775013376136971 girl: 0.3224986623863028 mean = [boy = 0.677501,girl = 0.322499] var : child2 Probabilities: boy: 0.6508828250401284 girl: 0.3491171749598716 mean = [boy = 0.650883,girl = 0.349117] var : p Probabilities: false: 0.6716158373461745 true: 0.3283841626538256 mean = [false = 0.671616,true = 0.328384] The probability that both children are boys is 1/3. */ go2 ?=> reset_store, run_model(10_000,$model2,[show_probs_trunc,mean]), nl, % show_store_lengths,nl, % fail, nl. go2 => true. model2() => N = 2, Gender = [condt(flip(1/2),boy,girl) : _ in 1..N], Child1 = Gender[1], Child2 = Gender[2], P = check((Child1 == boy, Child2 == boy)), observe( (Child1 == boy ; Child2 == boy) ), if observed_ok then add("child1",Child1), add("child2",Child2), add("p",P) end. /* """ "Suppose I have two kids, lets call them Bouba and Kiki", says Dr. Cooper, "and suppose Bouba is a girl !" What is the probability that I have two daughters?" """ var : bouba Probabilities: girl: 1.0000000000000000 mean = [girl = 1.0] var : kiki Probabilities: boy: 0.5025927403270841 girl: 0.4974072596729158 mean = [boy = 0.502593,girl = 0.497407] var : p Probabilities: false: 0.5025927403270841 true: 0.4974072596729158 mean = [false = 0.502593,true = 0.497407] This case is the same as in case 1, i.e. probability (p) is 1/2. (Then fact that they was named by concrete names did not discern them further.) */ go3 ?=> reset_store, run_model(10_000,$model3,[show_probs_trunc,mean]), nl, % show_store_lengths,nl, % fail, nl. go3 => true. model3() => N = 2, Gender = [condt(flip(1/2),boy,girl) : _ in 1..N], Bouba = Gender[1], Kiki = Gender[2], P = check((Bouba == girl, Kiki == girl)), observe(Bouba == girl), if observed_ok then add("bouba",Bouba), add("kiki",Kiki), add("p",P) end.