/* Probability challenge in Picat. https://medium.com/illumination/can-you-solve-this-probability-challenge-6a112e661951 """ [ A B Chest with 100% gold Chest with 50% gold and 50% silver ] You randomly choose a treasure chest to open, and then randomly choose a coin from that treasure chest. If the coin you choose is gold, then what is the probability that you chose chest A?" ... Solution 1 Here’s an intuitive explanation. There are two ways to get a gold coin: from chest A (from which we have a 100% chance), or from chest B (from which we have a 50% chance). Since we are twice as likely to get a gold coin if we are choosing from chest A, the odds that we choose from chest A are 2:1. So the probability is 2/3. ... But wait Captain, here’s a bonus problem: A family has two children. Given that one of the children is a boy, what is the probability that both children are boys? """ Cf - ppl_bertrands_paradox.pi - ppl_bertrands_paradox_resampling.pi - my Gamble model gamble_probability_challenge.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. /* var : chest Probabilities: a: 0.6689516129032258 b: 0.3310483870967742 mean = [a = 0.668952,b = 0.331048] var : pick Probabilities: gold: 1.0000000000000000 mean = [gold = 1.0] */ go ?=> reset_store, run_model(10_000,$model,[show_probs_trunc,mean]), nl, % show_store_lengths,nl, % fail, nl. go => true. model() => Chest = uniform_draw([a,b]), Pick = cond(Chest == a, categorical([100,0],[gold,silver]), categorical([50,50],[gold,silver])), observe(Pick == gold), if observed_ok then add("chest",Chest), add("pick",Pick) end. /* Bonus problem """ A family has two children. Given that one of the children is a boy, what is the probability that both children are boys? """ goal = go2 var : child1 Probabilities: boy: 0.6662232273513370 girl: 0.3337767726486630 mean = [boy = 0.666223,girl = 0.333777] var : child2 Probabilities: boy: 0.6628974324863642 girl: 0.3371025675136358 mean = [boy = 0.662897,girl = 0.337103] var : p Probabilities: false: 0.6708793401622988 true: 0.3291206598377012 mean = [false = 0.670879,true = 0.329121] Cf - ppl_daughter_or_son.pi - ppl_two_children_problem.pi - ppl_how_many_sons.pi */ go2 ?=> reset_store, run_model(10_000,$model2,[show_probs_trunc,mean]), nl, % show_store_lengths,nl, % fail, nl. go2 => true. model2() => Child1 = categorical([1/2,1/2],[boy,girl]), Child2 = categorical([1/2,1/2],[boy,girl]), % "One of the children is a boy" observe( (Child1 == boy ; Child2 == boy)), P = check( (Child1 == boy, Child2 == boy)), if observed_ok then add("child1",Child1), add("child2",Child2), add("p",P) end.