/* M & M problem in Picat. From Think Bayes, page 6f. """ M&M’s are small candy-coated chocolates that come in a variety of colors. Mars, Inc., which makes M&M’s, changes the mixture of colors from time to time. In 1995, they introduced blue M&M’s. Before then, the color mix in a bag of plain M&M’s was 30% Brown, 20% Yellow, 20% Red, 10% Green, 10% Orange, 10% Tan. Afterward it was 24% Blue , 20% Green, 16% Orange, 14% Yellow, 13% Red, 13% Brown. Suppose a friend of mine has two bags of M&M’s, and he tells me that one is from 1994 and one from 1996. He won’t tell me which is which, but he gives me one M&M from each bag. One is yellow and one is green. What is the probability that the yellow one came from the 1994 bag? """ Page 7 (the table): The answer is 20/27: ~0.74074. Cf my Gamble model gamble_m_and_m_problem.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. /* Model 1: var : mix 1 Probabilities: mix1994: 0.7419122933141624 mix1996: 0.2580877066858375 mean = [mix1994 = 0.741912,mix1996 = 0.258088] var : mix 2 Probabilities: mix1996: 0.7419122933141624 mix1994: 0.2580877066858375 mean = [mix1996 = 0.741912,mix1994 = 0.258088] */ go ?=> reset_store, run_model(100_000,$model,[show_probs_trunc,mean]), nl, % show_store_lengths, % fail, nl. go => true. model() => Colors = [brown, yellow, red, green,orange, tan, blue], Mixes = [mix1994,mix1996], % Mix the two bags Mix = draw_without_replacement(2,Mixes), % First pick a candy from Mix[1] and then pick one from the other bag (Mix[2]) % Check the colors of each candy Color = [ cond(Mix[I]==mix1994, categorical([30,20,20,10,10,10,0],Colors), categorical([13,14,13,20,16,0,24],Colors)) : I in 1..2], % The first candy is yellow, the second is green observe(Color[1] == yellow,Color[2] == green), % From which mix did we took these candies? if observed_ok then add("mix 1",Mix[1]), add("mix 2",Mix[2]) end.