/* Brain Twister #44: Dice and cards in Picat. https://enigmaticcode.wordpress.com/2024/11/01/braintwister-44-dice-and-cards/ """ From New Scientist #3515, 2nd November 2024 On each turn of a game, we roll three standard dice with faces numbered 1 to 6 and add up the numbers shown. (a) What is the average (mean) value of that total over a long game? Now suppose instead of rolling dice, we draw three cards from a six-card deck where the cards are numbered 1 to 6. (b) If we put each card back after drawing it and shuffle before drawing another card, does this change the expected value? (c) If we instead draw three cards without replacement (so the probabilities are no longer independent), what is the average value of the total? """ Picat> X = sum_prob_dist_mean(1,6,3) X = 10.5 All probabilities: Picat> pdf_all($sum_prob_dist(1,6,3),0.001,0.9999999).sort_down(2).printf_list 11 0.125 10 0.125 12 0.115740740740741 9 0.115740740740741 13 0.097222222222222 8 0.097222222222222 14 0.069444444444444 7 0.069444444444444 15 0.046296296296296 6 0.046296296296296 16 0.027777777777778 5 0.027777777777778 17 0.013888888888889 4 0.013888888888889 18 0.00462962962963 3 0.00462962962963 Cf - ppl_sum_prob_dist.pi - my Gamble model gamble_brain_twister_44_dice_and_cards.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. /* """ On each turn of a game, we roll three standard dice with faces numbered 1 to 6 and add up the numbers shown. (a) What is the average (mean) value of that total over a long game? """ var : s Probabilities: 10: 0.1239000000000000 11: 0.1218000000000000 9: 0.1195000000000000 12: 0.1162000000000000 8: 0.0979000000000000 13: 0.0947000000000000 14: 0.0703000000000000 7: 0.0686000000000000 6: 0.0481000000000000 15: 0.0457000000000000 16: 0.0292000000000000 5: 0.0275000000000000 17: 0.0157000000000000 4: 0.0129000000000000 18: 0.0040000000000000 3: 0.0040000000000000 mean = 10.5087 */ go ?=> reset_store, run_model(10_000,$model,[show_probs,mean % , % show_percentiles, % show_hpd_intervals,hpd_intervals=[0.94], % show_histogram, % min_accepted_samples=1000,show_accepted_samples=true ]), nl, % show_store_lengths,nl, % fail, nl. go => true. model() => N = 3, X = dice_n(6,N), S = X.sum, add("s",S). /* """ Now suppose instead of rolling dice, we draw three cards from a six-card deck where the cards are numbered 1 to 6. (b) If we put each card back after drawing it and shuffle before drawing another card, does this change the expected value? """ No, the estimated value is the same as in a). var : s Probabilities: 11: 0.1232000000000000 10: 0.1217000000000000 12: 0.1194000000000000 9: 0.1172000000000000 8: 0.0964000000000000 13: 0.0953000000000000 14: 0.0733000000000000 7: 0.0679000000000000 6: 0.0478000000000000 15: 0.0437000000000000 5: 0.0267000000000000 16: 0.0266000000000000 17: 0.0167000000000000 4: 0.0146000000000000 18: 0.0051000000000000 3: 0.0044000000000000 mean = 10.5201 */ go2 ?=> reset_store, run_model(10_000,$model2,[show_probs,mean % , % show_percentiles, % show_hpd_intervals,hpd_intervals=[0.94], % show_histogram, % min_accepted_samples=1000,show_accepted_samples=true ]), nl, % show_store_lengths,nl, % fail, nl. go2 => true. model2() => N = 3, X = resample(N, 1..6), S = X.sum, add("s",S). /* """ (c) If we instead draw three cards without replacement (so the probabilities are no longer independent), what is the average value of the total? """ This is also the same estimated value. Though this has has a little different probability distribution than for a) and b). var : s Probabilities: 10: 0.1527000000000000 11: 0.1523000000000000 12: 0.1508000000000000 9: 0.1467000000000000 13: 0.1029000000000000 8: 0.0989000000000000 14: 0.0498000000000000 6: 0.0496000000000000 15: 0.0482000000000000 7: 0.0481000000000000 mean = 10.5156 */ go3 ?=> reset_store, run_model(10_000,$model3,[show_probs,mean % , % show_percentiles, % show_hpd_intervals,hpd_intervals=[0.94], % show_histogram, % min_accepted_samples=1000,show_accepted_samples=true ]), nl, % show_store_lengths,nl, % fail, nl. go3 => true. model3() => N = 3, X = draw_without_replacement(N, 1..6), S = X.sum, add("s",S).