/* Either a spade or an ace in Picat. From http://www.statistics101.net/statistics101web_000007.htm """ From CliffsQuickReview Statistics, p. 43, example 5 What is the probability of drawing either a spade or an ace from a deck of cards? Calculated result: 16/52 = 0.308 """ p(spade) + p(ace) - p(ace of spades): 13/52 + 4/52 - 1/52 = 0.30769230769230769231 Cf my Gamble model gamble_either_a_spade_or_and_ace.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 : p Probabilities: false: 0.6914000000000000 true: 0.3086000000000000 mean = [false = 0.6914,true = 0.3086] var : card Probabilities: 0: 0.6914000000000000 1: 0.3086000000000000 mean = 0.3086 */ go ?=> reset_store, run_model(10_000,$model,[show_probs_trunc,mean]), nl, % show_store_lengths,nl, % fail, nl. go => true. model() => Card = categorical([16,36],[1,0]), P = check(Card==1), add("p",P), add("card",Card). /* Another approach var : spade Probabilities: false: 0.7539000000000000 true: 0.2461000000000000 mean = [false = 0.7539,true = 0.2461] var : ace Probabilities: false: 0.9235000000000000 true: 0.0765000000000000 mean = [false = 0.9235,true = 0.0765] var : p Probabilities: false: 0.6978000000000000 true: 0.3022000000000000 mean = [false = 0.6978,true = 0.3022] */ go2 ?=> reset_store, run_model(10_000,$model2,[show_probs_trunc,mean]), nl, % show_store_lengths,nl, % fail, nl. go2 => true. model2() => Card = random_integer(52), Spade = check(Card < 13), % Is this a spade? Ace = check(Card mod 13 == 0), % This is an ace P = check((Spade ; Ace)), add("spade",Spade), add("ace",Ace), add("p",P).