/* Who ordered the pizza problem in Picat. From https://stackoverflow.com/questions/77261872/improper-prolog-logic-for-logic-test """ Donna, Danny, David, and Doreen were seated at a table in a restaurant. The men sat across from each other, as did the women. They each ordered a different main course with a different beverage. in addition, - Doreen sat beside the person who ordered steak. - The chicken came with a Coke. - The person with the lasagna sat across from the person with milk. - David never drinks coffee - Donna only drinks water - Danny could not afford to order steak. Who ordered the pizza? """ people = [1,2,3,4] mainCourse = [4,2,3,1] beverage = [2,4,3,1] pizza = 1 Donna Pizza Water Doreen Chicken Coke Danny Lasagne Coffee David Steak Milk pizza = 1 = Donna This program was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import cp. main => go. go => People = [Donna,Doreen,Danny,David], People = [1,2,3,4], PeopleStr = ['Donna','Doreen','Danny','David'], MainCourse = [Steak,Chicken,Lasagne,Pizza], MainCourse :: 1..4, MainCourseStr = ['Steak','Chicken','Lasagne','Pizza'], Beverage = [Coke,Milk,Coffee,Water], Beverage :: 1..4, BeverageStr = ['Coke','Milk','Coffee','Water'], all_different(MainCourse), all_different(Beverage), % - Doreen sat beside the person who ordered steak. Doreen #!= Steak, Steak #!= Donna, % Steak was ordered by a man % (Steak #= Danny #\/ Steak #= David), % not needed % - The chicken came with a Coke. Chicken #= Coke, % - The person with the lasagna sat across from the person with milk. % (i.e. same sex for Lasagne and Milk) Lasagne #!= Milk, (Donna #= Lasagne #/\ Doreen #= Milk) #\/ (Doreen #= Lasagne #/\ Donna #= Milk) #\/ (Danny #= Lasagne #/\ David #= Milk) #\/ (David #= Lasagne #/\ Danny #= Milk), % - David never drinks coffee David #!= Coffee, % - Donna only drinks water Donna #= Water, % - Danny could not afford to order steak. Danny #!= Steak, Vars = MainCourse ++ Beverage, solve(Vars), println(people=People), println(mainCourse=MainCourse), println(beverage=Beverage), nl, % For presentation assignment(MainCourse,MainCourseInv), assignment(Beverage,BeverageInv), foreach(I in People) printf("%w %w %w\n",PeopleStr[I],MainCourseStr[MainCourseInv[I]],BeverageStr[BeverageInv[I]]) end, println(pizza=Pizza=PeopleStr[Pizza]), nl, fail, nl.