/* Meeting collegues at office in Picat. https://www.reddit.com/r/Probability/comments/1fksuqo/probably_of_two_colleagues_being_in_the_office_on/ """ Probably of two colleagues being in the office on the same days If two different colleagues independently chose 3 days to go into an office Whats the probability that At least 1 match at least 2 match At least 3 match 1 is 100% as no matter what you will have 1 matching day but beyond that I’m slightly stumped """ Cf my Gamble model gamble_meeting_collegues_at_office.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. /* Some different scenarios: [num_people = 2,workdays = 5,num_in_office = 3] var : num matches Probabilities: 2: 0.5985000000000000 1: 0.3037000000000000 3: 0.0978000000000000 mean = 1.7941 [num_people = 2,workdays = 10,num_in_office = 5] var : num matches Probabilities: 3: 0.3989000000000000 2: 0.3974000000000000 1: 0.0987000000000000 4: 0.0975000000000000 5: 0.0040000000000000 0: 0.0035000000000000 mean = 2.5002 [num_people = 2,workdays = 30,num_in_office = 10] var : num matches Probabilities: 3: 0.3101000000000000 4: 0.2697000000000000 2: 0.1869000000000000 5: 0.1312000000000000 1: 0.0534000000000000 6: 0.0368000000000000 0: 0.0063000000000000 7: 0.0053000000000000 8: 0.0003000000000000 mean = 3.3526 [num_people = 3,workdays = 5,num_in_office = 3] var : num matches Probabilities: 1: 0.5784000000000000 2: 0.2345000000000000 0: 0.1781000000000000 3: 0.0090000000000000 mean = 1.0744 [num_people = 4,workdays = 5,num_in_office = 3] var : num matches Probabilities: 1: 0.4886000000000000 0: 0.4311000000000000 2: 0.0791000000000000 3: 0.0012000000000000 mean = 0.6504 */ go ?=> member([NumPeople,Workdays,NumInOffice],[[2,5,3], [2,10,5], [2,30,10], [3,5,3], [4,5,3] ]), println([num_people=NumPeople,workdays=Workdays,num_in_office=NumInOffice]), reset_store, run_model(10_000,$model(NumPeople,Workdays,NumInOffice),[show_probs_trunc,mean]), nl, % show_store_lengths,nl, fail, nl. go => true. model(NumPeople,Workdays,NumInOffice) => Days = 1..Workdays, People = [draw_without_replacement(NumInOffice,Days).sort : _ in 1..NumPeople], NumMatches = reduce(intersection,People).len, add("num matches",NumMatches).