/* Car in box in Picat. From https://medium.com/puzzle-sphere/can-you-find-the-right-box-d01521f17015 """ There are 3 boxes, exactly one of which has a car. You can keep the car if you pick the correct box! On each box, there is a statement, exactly one of which is true. - Box 1: The car is in this box. - Box 2: The car is not in this box. - Box 3: The car is not in box 1. Which box has the car? """ Cf - CP model car_in_box.pi - my Gamble model gamble_car_in_box.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. /* Num accepted samples: 1000 Total samples: 22641 (0.044%) var : car Probabilities: 2: 1.0000000000000000 mean = 2.0 var : boxes Probabilities: [0,0,1]: 1.0000000000000000 mean = [[0,0,1] = 1.0] */ go ?=> reset_store, run_model(10_000,$model,[show_probs_trunc,mean, % show_percentiles, % show_hpd_intervals,hpd_intervals=[0.94], % show_histogram, min_accepted_samples=1000,show_accepted_samples=false ]), nl, % show_store_lengths,nl, % fail, nl. go => true. model() => N = 3, Car = random_integer1(N), % Boxes = uniform_draw_n([0,1],N), % observe(Boxes.sum == 1), Boxes = uniform_draw([[0,0,1],[0,1,0],[1,0,0]]), % Box 1: The car is in this box. equivalence(Boxes[1] == 1,Car == 1), % Box 2: The car is not in this box. equivalence(Boxes[2] == 1,Car != 2), % Box 3: The car is not in box 1. equivalence(Boxes[3] == 1,Car != 1), if observed_ok then add("car",Car), add("boxes",Boxes), end.