/* Swimming and biking problem in Picat. From Prolog code http://www.anselm.edu/internet/compsci/faculty_staff/mmalita/HOMEPAGE/logic/aa1.txt """ Author: (sol MM) Title: Contest: swimming and biking From: Prof. Adrian Atanasiu: http://www.galaxyng.com/potw/ Four students competed in two different tests: swimming and biking. Can you establish the final order for each test? 1. Andrew did not win any competition. 2. The person who won the swimming contest was the third at the bike competition. 3. Andrew did better than Corey at the swimming contest, but Corey was better than Andrew at the bike contest. 4. Corey was never the last. 5. Doru [Dan?] won the bike contest, but Sandy was better than him at the swimming contest. What was the winning order in the swimming and bike contest? ?- start,fail. Swimming contest=[sandy,andrew,corey,dan] Bike contest= [dan,corey,sandy,andrew] no """ This Picat model was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import util. % import cp. main => go. go => sol(S,B), print('Swimming contest='), println(S), print('Bike contest= '), println(B), nl. students(Students) => Students = [sandy,andrew,corey,dan]. sol(Swim,Bike) => students(St), set_equal(Swim,St), Bike = new_list(St.length), % hakank: added this set_equal(Bike,St), Swim=[Hs|_],andrew!=Hs, Bike=[Hb|_],andrew!=Hb, Bike=[_,_,Hs,_], before(andrew,corey,Swim), before(corey,andrew,Bike), append(_,[Ls],Swim), Ls!=corey, append(_,[Lb],Bike), Lb!=corey, Bike=[dan|_], before(sandy,dan,Swim). set_equal(P1,P2) => permutation(P1,P2). % From % http://www.anselm.edu/internet/compsci/faculty_staff/mmalita/HOMEPAGE/logic/bibmm.txt /* before (X,Y,List). Checks if X is before Y in the List. Starts from Left to right (normal order..). ?-before(a,c,[m,a,v,c,d]). yes */ before(X,Y,L) => append(_,[X|T],L), member(Y,T).