/* Meeting problem in Picat. (I'm not sure about the source. The page I got it from does not exist anymore.) """ Let's say that 4 people agree to meet between 3:00 P.M. and 4:00 P.M.. One man can wait for 10 minutes. Another can wait for 15 minutes. Another can wait for 20 Minutes, and another still can wait for 30 minutes. What is the probability that all 4 will meet? """ This problem was originally done using R (see http://www.hakank.org/sims/simulering.html) which gave the probability of meeting: 0.073. Cf - ppl_meeting_problem2.pi - my Gamble model gamble_meeting_problem.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 : prob Probabilities: false: 0.9170000000000000 true: 0.0830000000000000 mean = [false = 0.917,true = 0.083] var : size Probabilities (truncated): 0: 0.9170000000000000 1: 0.0142000000000000 2: 0.0136000000000000 3: 0.0109000000000000 ......... 8: 0.0045000000000000 11: 0.0034000000000000 9: 0.0034000000000000 10: 0.0025000000000000 mean = 0.3648 var : min val Probabilities (truncated): 0: 0.9170000000000000 51: 0.0027000000000000 55: 0.0026000000000000 59: 0.0025000000000000 ......... 7: 0.0003000000000000 16: 0.0002000000000000 10: 0.0002000000000000 6: 0.0001000000000000 mean = 3.2191 var : max val Probabilities (truncated): 0: 0.9170000000000000 60: 0.0089000000000000 55: 0.0034000000000000 40: 0.0026000000000000 ......... 13: 0.0004000000000000 14: 0.0003000000000000 12: 0.0002000000000000 11: 0.0001000000000000 mean = 3.5009 */ go ?=> reset_store, run_model(20_000,$model,[show_probs_trunc,mean]), nl, % show_store_lengths, % fail, nl. go => true. model() => W = [10,15,20,30], N = W.len, % Start times + wait times Ps = [ R..min(R+W[I],60) : I in 1..N, R=random_integer(60)+1], % Is there a common time slot? Common = reduce(intersection,Ps), Size = Common.len, Prob = check(Size > 0), MinVal = cond(Common.len>0,Common.min,0), MaxVal = cond(Common.len>0,Common.max,0), add("prob",Prob), add("size",Size), add("min val",MinVal), add("max val",MaxVal).