/* Scholarship problem in Picat. From Russ Abbott, Jungsoo Lim, Jay Patel "Constraint programming as the most reliable platform for Web Intelligence" """ * There are four students: Ada, Emmy, Lynn, and Marie. Each has a scholarship and a major. No two students have the same scholarship or the same major. * The scholarships and majors are $25,000, $30,000, $35,000 and $40,000 and Bio, CS, Math, and Phys. From the clues listed below, determine which student studies which major and the amount of each student’s scholarship. ... [Clues] - The student who studies Phys gets a smaller scholarship than Emmy - Emmy studies either Math or Bio - The Stdnt who studies CS has a $5,000 larger scholarship than Lynn. - Marie gets $10,000 more than Lynn - Ada has a larger scholarship than the Stdnt who studies Bio """ Also see: https://github.com/RussAbbott/pylog_FD This Picat model was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import cp. main => go. go ?=> N = 4, Students = [Ada,Emmy,Lynn,Marie], Students :: 1..N, StudentsS = ["Ada","Emmy","Lynn","Marie"], Majors = [Bio,CS,Math,Phys], Majors :: 1..N, MajorsS = ["Bio","CS","Math","Phys"], Scholarship = [25000,30000,35000,40000], all_different(Students), all_different(Majors), % % Clues % % The student who studies Phys gets a smaller scholarship than Emmy element(Phys,Students,PhysStudent), element(Emmy,Scholarship,EmmyScholarship), element(PhysStudent,Scholarship,PhysStudentScholarship), PhysStudentScholarship #< EmmyScholarship, % Emmy studies either Math or Bio Emmy #= Math #\/ Math #= Bio, % The Stdnt who studies CS has a $5,000 larger scholarship than Lynn. element(CS,Scholarship,CSScholarship), element(Lynn,Scholarship,LynnScholarship), CSScholarship #= LynnScholarship + 5000, % Marie gets $10,000 more than Lynn element(Marie,Scholarship,MarieScholarship), MarieScholarship #= LynnScholarship + 10000, % Ada has a larger scholarship than the Stdnt who studies Bio element(Ada,Scholarship,AdaScholarship), element(Bio,Scholarship,BioScholarship), AdaScholarship #> BioScholarship, Vars = Students ++ Majors, solve($[ff,split],Vars), println(students=Students), println(majors=Majors), nl, foreach(I in 1..N) element(Student,Students,I), element(Major,Majors,I), StudentMajor = StudentsS[Student] ++ "/" ++ MajorsS[Major], printf("\t%d.%-12w($%d Scholarship)\n",I, StudentMajor,Scholarship[I]) end, nl, fail, nl. go => true.