/* Invisible dice in Picat. From https://brainstellar.com/puzzles/probability/24 """ Invisible Dice I bought two fair six-sided dice. Keeping the first one untouched, I modified the second die, by erasing each face and writing a number of my own. Now, the sum of outcomes of the two dice is equally likely an integer between 1 and 12. Can you deduce the numbers written on the modified die? Note: For each dice, each face is equally likely to turn up after a toss. """ Cf my CP model invisible_dice.pi 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. /* Num accepted samples: 10 Total samples: 16534 (0.001%) var : die2 Probabilities: [0,0,0,6,6,6]: 1.0000000000000000 var : sums Probabilities: [1,1,1,2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7,8,8,8,9,9,9,10,10,10,11,11,11,12,12,12]: 1.0000000000000000 */ go ?=> reset_store, run_model(10_000,$model,[show_probs, % mean, % show_percentiles,show_histogram, % show_hpd_intervals,hpd_intervals=[0.94], min_accepted_samples=10,show_accepted_samples=true ]), nl, % show_store_lengths,nl, % fail, nl. go => true. model() => Die1 = 1..6, % Generate 6 random number from 0..6 Die2 = random_integer_n(7,6).sort, % Get all possible combinations (and sort them) Sums = [ D1+D2 : D1 in Die1, D2 in Die2].sort, Freq = Sums.get_freq, % Get their frequencies % Each sum 2..12 should have exactly 36/12 = 3 occurrences foreach(I in 1..12) observe(Freq.get(I,0) == 3) end, if observed_ok then add("die2",Die2), add("sums",Sums), end.