/* Binomial dice in Picat. https://reference.wolfram.com/language/ref/BinomialDistribution.html """ Two players roll dice. If the total of both numbers is less than 10, the second player is paid 4 cents; otherwise the first player is paid 9 cents. Is the game fair?: ... The game is not fair: mean scores are 1.5 and 3.33333. """ Cf my Gamble model gamble_binomial_dice2.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 : player1 Probabilities: 4: 0.1704000000000000 2: 0.1678000000000000 1: 0.1676000000000000 6: 0.1663000000000000 3: 0.1646000000000000 5: 0.1633000000000000 mean = 3.4929 var : player2 Probabilities: 6: 0.1730000000000000 1: 0.1726000000000000 5: 0.1675000000000000 4: 0.1659000000000000 2: 0.1644000000000000 3: 0.1566000000000000 mean = 3.5103 var : total Probabilities (truncated): 7: 0.1609000000000000 6: 0.1395000000000000 8: 0.1386000000000000 9: 0.1115000000000000 3: 0.0553000000000000 11: 0.0535000000000000 2: 0.0309000000000000 12: 0.0301000000000000 mean = 7.0032 var : player1_sum Probabilities: 0: 0.8294000000000000 9: 0.1706000000000000 mean = 1.5354 var : player2_sum Probabilities: 4: 0.8294000000000000 0: 0.1706000000000000 mean = 3.3176 var : fair Probabilities: false: 1.0000000000000000 mean = [false = 1.0] */ go ?=> reset_store, run_model(10_000,$model,[show_probs_trunc,mean, presentation=[player1,player2,total,player1_sum,player2_sum,fair]]), nl, % fail, nl. go => true. model() => Limit = 10, Player1 = random_integer1(6), Player2 = random_integer1(6), Total = Player1 + Player2, Player1Sum = 0, Player2Sum = 0, if Total < Limit then Player2Sum := 4, else Player1Sum := 9, end, Fair = check(Player1Sum == Player2Sum), add_all([ [player1,Player1], [player2,Player2], [total,Total], [player1_sum,Player1Sum], [player2_sum,Player2Sum], [fair,Fair]]).