/* Birthday in Picat. From PSI test/birthday3.psi For d=7,p=3 (method:enumerate) duplicate Marginal: false : 0.6122448979591837 true : 0.3877551020408163 Cf my Gamble model gamble_birthday2.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 : birthdays Probabilities (truncated): [0,1,0,0,0,1,1]: 0.0210000000000000 [0,0,1,1,0,1,0]: 0.0200000000000000 [1,0,1,0,0,0,1]: 0.0193000000000000 [1,1,0,0,0,0,1]: 0.0189000000000000 ......... [0,0,0,0,0,3,0]: 0.0027000000000000 [0,0,3,0,0,0,0]: 0.0025000000000000 [0,0,0,0,0,0,3]: 0.0024000000000000 [3,0,0,0,0,0,0]: 0.0023000000000000 var : prob Probabilities: 3: 0.6089000000000000 2: 0.3729000000000000 1: 0.0182000000000000 mean = 2.5907 */ go ?=> reset_store, run_model(10_000,$model,[show_probs_trunc,mean]), nl, % show_store_lengths,nl, % fail, nl. go => true. model() => D = 7, % Days P = 3, % People Birthday = random_integer1_n(D,P), Birthdays = [ [ cond(I == Birthday[J],1,0) : J in 1..P].sum : I in 1..D ], println(birthdays=Birthdays), Prob = [ cond(B > 0,1,0) : B in Birthdays].sum, add("birthdays",Birthdays), add("prob",Prob).