/* Mr Shearer's class in Picat. https://minerva-demo.github.io/#category=Probability&index=2 """ Question Three-fourths of the students in Mr. Shearer's class have brown hair and six-sevenths of his students are right-handed. If Mr. Shearer's class has 28 students, what is the smallest possible number of students that could be both right-handed and have brown hair? ... Reference answer Mr. Shearer has 3/4(28)=21 students with brown hair and 6/7(28)=24 students who are right-handed. Since there are 28−24=4 left-handed students, at most 4 of the 21 brown-haired students are left-handed. Therefore, at least 17 of them are right-handed. Final Answer: The final answer is 17. ... Problem source: MATH Counting & Probability Level 1 """ Cf my Gamble model gamble_mr_shearers_class.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 both Probabilities: 18: 0.4730000000000000 17: 0.2960000000000000 19: 0.1920000000000000 20: 0.0380000000000000 21: 0.0010000000000000 mean = 17.975 numBoth = [18 = 0.473,17 = 0.296,19 = 0.192,20 = 0.038,21 = 0.001] min_value = 17 */ go ?=> reset_store, run_model(10_000,$model,[show_probs,mean, % show_percentiles, % show_hpd_intervals,hpd_intervals=[0.94], % show_histogram, min_accepted_samples=1000,show_accepted_samples=false ]), nl, NumBoth = get_store().get("num both").get_probs, println(numBoth=NumBoth), println(min_value=min(NumBoth).first), % show_store_lengths,nl, % fail, nl. go => true. model() => NumStudents = 28, % 3/4 of the class has brown hair HasBrownHair = bern_n(3/4,NumStudents), % Enforce this observe( HasBrownHair.sum * 4 == 3 * NumStudents ), % 6/7 of the class are right handed IsRightHanded = bern_n(6/7,NumStudents), % Enforce this observe( IsRightHanded.sum * 7 == 6 * NumStudents ), % How many has both brown hair and are right handed? NumBoth = [cond( (HasBrownHair[S]==1,IsRightHanded[S]==1),1,0) : S in 1..NumStudents].sum, if observed_ok then add("num both",NumBoth) end.