/* Two heads in three coin tosses in Picat. From Statistics101 (Resample Stats) http://www.statistics101.net/QuickReference.pdf Page 9 """ (S)ay you wanted to know the probability of getting exactly two heads in a toss of three coins. """ Picat> println(binomial_dist_pdf(3,1/2,2).and_rat) 0.375 (3 / 8) Cf my Gamble model gamble_two_heads_in_three_coin_tosses.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: 1: 0.3767000000000000 2: 0.3681000000000000 3: 0.1286000000000000 0: 0.1266000000000000 mean = 1.4987 var : p Probabilities: false: 0.6319000000000000 true: 0.3681000000000000 mean = 0.3681 theoretical = 0.375 (3 / 8) */ 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=true ]), nl, println(theoretical=binomial_dist_pdf(3,1/2,2).and_rat), % show_store_lengths,nl, % fail, nl. go => true. model() => Coin = [head,tail], Tosses = resample(3,Coin), C = count_occurrences(head,Tosses), P = check(C == 2), add("c",C), add("p",P).