/* Rolling dice problem in Picat. From https://dtai.cs.kuleuven.be/problog/tutorial/basic/03_dice.html """ We now consider yet another way to model dice, using fair ones only. This representation allows for convenient use of the results in arithmetic expressions, e.g., to add up the results from several dice. We query for the probabilities of the possible sums we can get from two dice given that the first number is even and the second odd. """ This is the exact probabilities (from my Racket/Gamble model gamble_rolling_dice3.rkt) (7 : 1/3 (0.3333333333333333)) (5 : 2/9 (0.2222222222222222)) (9 : 2/9 (0.2222222222222222)) (3 : 1/9 (0.1111111111111111)) (11 : 1/9 (0.1111111111111111)) (mean: 7.0) This is a port of my Racket/Gamble model gamble_rolling_dice3.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. main => go. /* Var S: Probabilities: 7: 0.33380421806605648 (16777 / 50260) 5: 0.22347791484281734 (2808 / 12565) 9: 0.22089136490250696 (793 / 3590) 3: 0.11215678471945881 (5637 / 50260) 11: 0.10966971746916036 (1378 / 12565) mean = 6.98488 */ go ?=> reset_store, run_model(200_000,$model,[show_probs_rat,mean]), fail, nl. go => true. roll(D) = dice(6). model() => D1 = roll("d1"), D2 = roll("d2"), if even(D1), odd(D2) then S = D1 + D2, add("S",S) end.