/* Nine spades and four clubs in Picat. From Statistics101 """ Compute the probability of getting in a 13 card hand: Nine cards to be spades and four to be clubs. Order does not matter. From Resampling: The New Statistics, Julian Simon p. 125 (Assumes that the numbers 1 through 13 represent spades.) """ Cf my Gamble model gamble_nine_spades_four_clubs.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 : num spades Probabilities (truncated): 3: 0.2506500000000000 4: 0.2128500000000000 2: 0.2046000000000000 5: 0.1247000000000000 ......... 7: 0.0184000000000000 8: 0.0042000000000000 9: 0.0010500000000000 10: 0.0001000000000000 mean = 3.2555 var : num clubs Probabilities (truncated): 3: 0.2501500000000000 4: 0.2109500000000000 2: 0.2061000000000000 5: 0.1239500000000000 ......... 7: 0.0202000000000000 8: 0.0038000000000000 9: 0.0010500000000000 10: 0.0001000000000000 mean = 3.2516 var : p Probabilities: false: 0.9999500000000000 true: 0.0000500000000000 mean = 0.00005 */ go ?=> reset_store, run_model(20_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, % show_store_lengths,nl, % fail, nl. go => true. model() => % spades: 1, clubs: 2 (and we don't care about 3 and 4 representing diamonds and heart) Cards = [random_integer1(4) : _ in 1..13], NumSpades = count_occurrences(1,Cards), NumClubs = count_occurrences(2,Cards), P = check( (NumSpades==9, NumClubs==4)), add("num spades",NumSpades), add("num clubs",NumClubs), add("p",P).