/* Left some candles in Picat. https://brainstellar.com/puzzles/probability/216 """ You are taking out candies one by one from a jar that has 10 red candies, 20 blue candies, and 30 green candies in it. What is the probability that there is at least 1 blue candy and 1 green candy left in the jar when you have taken out all the red candies? Assume that the candies of the same color are indistinguishable from one another. Answer: 7/12 0.583333 """ Cf https://math.stackexchange.com/questions/1805078/candies-withdrawal-probability-for-a-particular-subsequence Cf my Gamble model gamble_left_some_candles.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. main => go. /* var : num blue Probabilities (truncated): 0: 0.3373000000000000 1: 0.2281000000000000 2: 0.1543000000000000 3: 0.1042000000000000 ......... 12: 0.0008000000000000 13: 0.0005000000000000 15: 0.0003000000000000 14: 0.0002000000000000 mean = 1.8131 var : p blue Probabilities: true: 0.6627000000000000 false: 0.3373000000000000 mean = [true = 0.6627,false = 0.3373] var : num green Probabilities (truncated): 0: 0.2497000000000000 1: 0.1987000000000000 2: 0.1475000000000000 3: 0.1115000000000000 ......... 20: 0.0003000000000000 22: 0.0001000000000000 21: 0.0001000000000000 19: 0.0001000000000000 mean = 2.6872 var : p green Probabilities: true: 0.7503000000000000 false: 0.2497000000000000 mean = [true = 0.7503,false = 0.2497] var : p Probabilities: true: 0.5833000000000000 false: 0.4167000000000000 mean = [true = 0.5833,false = 0.4167] */ go ?=> reset_store, run_model(10_000,$model,[show_probs_trunc,mean]), nl, % show_store_lengths,nl, % fail, nl. go => true. f(A) = Res => if not member(red,A) then Res = A else Res = f(A.tail) end. model() => Candles = ones(10,red) ++ ones(20,blue) ++ ones(30,green), S = draw_without_replacement(Candles.len,Candles), A = f(S), NumBlue = count_occurrences(blue,A), PBlue = check(NumBlue > 0), NumGreen = count_occurrences(green,A), PGreen = check(NumGreen > 0), P = check((PBlue,PGreen)), add("num blue",NumBlue), add("p blue",PBlue), add("num green",NumGreen), add("p green",PGreen), add("p",P).