/* Three people, ten floors in Picat. From Paolo Molignini: "Three people, ten floors, one puzzle: can you crack it?" https://medium.com/puzzle-sphere/three-people-ten-floors-one-puzzle-can-you-crack-it-8ac0ccd88e37 """ Three people get into an empty elevator at the first floor of a building that has 10 floors. Each presses the button for their desired floor (unless one of the others has already pressed that button). Assume that they are equally likely to want to go to floors 2 through 10 (independently of each other). What is the probability that the buttons for 3 consecutive floors are pressed? ... Summarizing, the probability of three consecutive buttons being pressed is then p = 42/729 ≈ 5.76%. """ Cf my Gamble model gamble_three_people_ten_floors.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 : desired floors Probabilities (truncated): [4,8,2]: 0.0025500000000000 [8,8,5]: 0.0021500000000000 [2,4,8]: 0.0021000000000000 [9,6,6]: 0.0020000000000000 [3,8,3]: 0.0020000000000000 [3,7,3]: 0.0020000000000000 [3,3,2]: 0.0020000000000000 [7,2,4]: 0.0019500000000000 ......... [5,9,7]: 0.0007500000000000 [2,5,3]: 0.0007500000000000 [10,4,10]: 0.0007000000000000 [7,6,3]: 0.0007000000000000 [10,4,5]: 0.0006500000000000 [8,3,6]: 0.0006500000000000 [10,6,3]: 0.0006000000000000 [2,3,2]: 0.0004500000000000 var : p Probabilities: false: 0.9457500000000000 true: 0.0542500000000000 mean = 0.05425 */ go ?=> reset_store, run_model(20_000,$model,[show_probs_trunc,mean,truncate_size=8 ]), nl, % show_store_lengths,nl, % fail, nl. go => true. model() => NumPeople = 3, NumFloors = 10, % floors 2..10 DesiredFloors = [ 2+random_integer(NumFloors-1) : _ in 1..NumPeople ], S = DesiredFloors.sort, % Probability of consecutive button presses P = check( (S[3]-S[2] == 1, S[2]-S[1]==1) ), add("desired floors",DesiredFloors), add("p",P).