/* Pepperoni pizza in Picat. From Statistics101 (Resampling Stats) File pepperoniPizza.txt """ If 24 pieces of sausage are randomly put onto a pizza that is sliced into 8 pieces (with none of the sausage pieces getting cut), what is the probability that your slice will have 3 pieces of sausage? From: "Statistics the Easy Way" Downing & Clark, 3rd edition, p. 58. -> probability: 0.2412 probability: 0.2338 probability: 0.239532 """ Cf my Gamble model gamble_pepperoni_pizza.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 : c Probabilities: 3: 0.2395000000000000 2: 0.2269000000000000 4: 0.1753000000000000 1: 0.1398000000000000 5: 0.1056000000000000 6: 0.0464000000000000 0: 0.0421000000000000 7: 0.0172000000000000 8: 0.0062000000000000 9: 0.0009000000000000 10: 0.0001000000000000 mean = 2.9988 var : p Probabilities: false: 0.7605000000000000 true: 0.2395000000000000 mean = 0.2395 */ go ?=> reset_store, run_model(10_000,$model,[show_probs,mean % , % show_percentiles, % show_hpd_intervals,hpd_intervals=[0.94], % show_histogram, % min_accepted_samples=1000,show_accepted_samples=true ]), nl, % show_store_lengths,nl, % fail, nl. go => true. model() => NumPieces = 24, NumSlices = 8, % Place 24 pieces of sausage (randomly) on the 8 slices Pizza = resample(NumPieces,1..NumSlices), % How many sausages are on my slice (slice 1)? C = count_occurrences(1,Pizza), P = check(C == 3), % Did I get 3 sausages? add("c",C), add("p",P).