/* You have a train to catch in Picat. From https://brainstellar.com/puzzles/probability/20 """ Spiderman has two close friends, Mary Jane & Gwen Stacy. After every mission, he rushes to the central subway. One line heads towards Mary's place, and another towards Stacy. Trains from each line leave every 10 minutes. Spiderman being impartial always boards the first train that leaves. However, he observes that he ends up visiting Mary Jane nine times more often than Gwen Stacy. Can you decipher why? """ This is a simple model for the problem. The unknown variable p is the percentages of trains towards Mary: Cf my Gamble model gamble_you_have_a_train_to_catch.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. main => go. /* var : p Probabilities (truncated): 0.991864109851617: 0.0010570824524313 0.989378034371279: 0.0010570824524313 0.989137934427528: 0.0010570824524313 0.988654043572439: 0.0010570824524313 ......... 0.496412876669122: 0.0010570824524313 0.491272706013301: 0.0010570824524313 0.470564024261152: 0.0010570824524313 0.454159552657128: 0.0010570824524313 mean = 0.830109 var : s Probabilities: mary: 0.9006342494714588 gwen: 0.0993657505285412 mean = [mary = 0.900634,gwen = 0.0993658] var : superman Probabilities: 6: 0.1078224101479915 3: 0.1057082452431290 1: 0.1057082452431290 10: 0.1025369978858351 7: 0.1004228329809725 2: 0.0993657505285412 8: 0.0983086680761099 4: 0.0972515856236787 9: 0.0919661733615222 5: 0.0909090909090909 mean = 5.45455 There is about 9 times more trains towards Mary than towards Gwen. */ go ?=> reset_store, run_model(10_000,$model,[show_probs_trunc,mean]), nl, % show_store_lengths,nl, % fail, nl. go => true. model() => % Number of trains N = 10, % Probability of a train towards Mary P = beta_dist(1,1), Trains = [ condt(flip(P), mary, gwen) : _ in 1..N], % When did Superman arrive to the station? % Times are 1..N Superman = random_integer1(N), % What train did he take? Towards Mary or towards Gwen? S = Trains[Superman], % Count the number of trains to Mary and Gwen CountMary = count_occurrences(mary,Trains), CountGwen = count_occurrences(gwen,Trains), % We observe 9 train towards Mary and 1 towards Gwen observe(CountMary == 9, CountGwen == 1), if observed_ok then add("p",P), add("superman",Superman), add("s",S) end.