/* Chuck-a-luck (Mosteller) in Picat. From Mosteller "Fifty Challenging problems in Probability" """ Chuck-a-Luck is a gambling game often played at carnivals and gambling houses. A player may bet on anyone of the numbers I, 2, 3, 4, 5, 6. Three dice are rolled. If the player's number appears on one, two, or three of the dice, he receives respectively one, two, or three times his original stake plus his own money back; otherwise he loses his stake. What is the player's expected loss per unit stake? (Actually the player may distribute stakes on several numbers, but each such stake can be regarded as a separate bet.) ... Thus you lose about 8% [17/216 ~ ~0.079] per play. """ Cf my Gamble model gamble_chuck_a_luck.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 : num hits Probabilities: 0: 0.5829000000000000 1: 0.3393000000000000 2: 0.0735000000000000 3: 0.0043000000000000 mean = 0.4992 var : outcome Probabilities: -1: 0.5829000000000000 1: 0.3393000000000000 2: 0.0735000000000000 3: 0.0043000000000000 mean = -0.0837 */ go ?=> reset_store, run_model(10_000,$model,[show_probs_trunc,mean]), nl, % show_store_lengths,nl, % fail, nl. go => true. model() => N = 3, % Num dice to roll UserNum = dice(), Roll = dice_n(N), NumHits = [cond(V == UserNum,1,0) : V in Roll].sum, % Outcome. We assume that the user bets 1 unit Outcome = cond(NumHits > 0,NumHits,-1), add("num hits",NumHits), add("outcome",Outcome).