/* Mr Shearer's class in Picat. From 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 WebPPL model http://hakank.org/webppl/mr_shearers_class.wppl This program was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ % import sat. % 1.0s % import cp. % too slow import mip. % GLPK: 0.18ss Cbc: 0.2 % import smt. % > 30min main => go. go => nolog, NumStudents = 28, % 3/4 of the class has brown hair HasBrownHair = new_list(NumStudents), HasBrownHair :: 0..1, sum(HasBrownHair)*4 #=3*NumStudents, % 6/7 of the class is right handed IsRightHanded = new_list(NumStudents), IsRightHanded :: 0..1, sum(IsRightHanded)*7 #= 6*NumStudents, % How many has both brown hair and are right handed? NumBoth #= sum([HasBrownHair[I]*IsRightHanded[I] #= 1 : I in 1..NumStudents ]), Vars = HasBrownHair ++ IsRightHanded, solve($[glpk,min(NumBoth),degree,down,report(printf("num_both:%d\n",NumBoth))],Vars), println(numBoth=NumBoth), nl.