/* Rolling two dice which sums to 8 in Picat. From https://medium.com/math-games/can-you-do-this-not-so-hard-probability-puzzle-40a502dfbc15 """ Suppose two fair dice are rolled and their sum is 8. What's the probability that at least one die lands on 4? """ The probability is 1/5 (0.2) Cf my Gamble model gamble_two_dice_sum.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. % import ordset. main => go. /* var : p Probabilities: false: 0.7986650221287093 true: 0.2013349778712907 mean = 0.201335 var : d1 Probabilities: 4: 0.2013349778712907 3: 0.2008271058550388 2: 0.2006094464195023 5: 0.1992309366611043 6: 0.1979975331930639 mean = 3.99318 var : d2 Probabilities: 4: 0.2013349778712907 5: 0.2008271058550388 6: 0.2006094464195023 3: 0.1992309366611043 2: 0.1979975331930639 mean = 4.00682 */ go ?=> reset_store, run_model(100_000,$model,[show_probs_trunc,mean ]), nl, % show_store_lengths,nl, % fail, nl. go => true. model() => D1 = dice(), D2 = dice(), S = D1 + D2, observe(S == 8), P = check( (D1 == 4, D2 == 4) ), if observed_ok then add("p",P), add("d1",D1), add("d2",D2), end.