/* Secret Santa puzzle in Picat. From Adrian Groza "Modelling Puzzles in First Order Logic" """ Puzzle 58. Secret Santa Five employees are side by side at their company secret santa. Find out what each one is drinking, which department they work and what the gift they got was. 1. Cody is the youngest employee. 2. The person gifted with a Book is Riley. 3. In the fifth position is the person drinking Juice. 4. Riley is next to the 41-year-old employee. 5. The 35-year-old employee is at one of the ends. 6. The man wearing the Red shirt is somewhere between the one who received a Mug and the one drinking Soft drink, in that order. 7. The one drinking Coffee is exactly to the left of who got a Notepad as a gift. 8. The man drinking Tea is exactly to the right of the man wearing the Blue shirt. 9. The employee wearing the Green shirt is next to the 28-year-old. 10. Steven is exactly to the right of Cody. 11. In the second position is the person drinking Water. 12. The employee that works at the R&D department is at the third position. 13. Tyler’s gift was a Mug. 14. The oldest employee is at the fifth position. 15. The person drinking Soft drink is at the third position. 16. Riley is next to the person who got a Tie as a gift. 17. The youngest employee is somewhere between the person drinking Water and the oldest person, in that order. 18. Jason is exactly to the right of the man wearing the Black shirt. 19. Cody is next to the one drinking Soft drink. 20. The man wearing Blue is somewhere to the left of who works at the Sales department. 21. The employee that works at the IT department was gifted a Notepad. 22. At the fourth position is the one drinking Tea. 23. The person gifted with chocolate is working at the HR department. 24. The man wearing the Green shirt is the person gifted with a tie. (taken from Brainzilla - www.brainzilla.com) """ This is a port of Groza's Mace 4 model. Solution: tyler black mug marketing 35 coffee jason red notepad it 41 water riley blue book r_and_d 28 soft_drink cody green tie sales 23 tea steven white chocolate hr 50 juice Note: In Groza's solution (page 125) there's a typo: The places of the names Riley and Cody should be switched; - It's Cody that's 23 years, not Riley - Riley is the one with the book, not Cody. This program 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 ?=> N = 5, Names = [Cody, Jason, Riley, Steven, Tyler], Names :: 0..N-1, NamesS = [cody, jason, riley, steven, tyler], all_different(Names), Colors = [Black, Blue, Green, Red, _White], Colors :: 0..N-1, ColorsS = [black, blue, green, red, white], all_different(Colors), Gifts = [Book, Chocolate, Mug, Notepad, Tie], Gifts :: 0..N-1, GiftS = [book, chocolate, mug, notepad, tie], all_different(Gifts), Department = [HR, IT, _Marketing, R_and_D, Sales], Department :: 0..N-1, DepartmentS = [hr, it, marketing, r_and_d, sales], all_different(Department), Ages = [Age_23, Age_28, Age_35, Age_41, Age_50], Ages :: 0..N-1, AgesS = [23, 28, 35, 41, 50], all_different(Ages), Drinks = [Coffee, Juice, Soft_drink, Tea, Water], Drinks :: 0..N-1, DrinksS = [coffee, juice, soft_drink, tea, water], all_different(Drinks), Cody #= Age_23, % Clue 1 Book #= Riley, % Clue 2 Juice #= 4, % Clue 3 neighbors(Riley,Age_41), % Clue 4 Age_35 #= 0 #\/ Age_35 #= 4, % Clue 5 between2(Mug,Red,Soft_drink), % Clue 6 left_neighbor(Notepad,Coffee), % Clue 7 right_neighbor(Blue,Tea), % Clue 8 neighbors(Green,Age_28), % Clue 9 right_neighbor(Cody,Steven), % Clue 10 Water #= 1, % Clue 11 R_and_D #= 2, % Clue 12 Tyler #= Mug, % Clue 13 Age_50 #= 4, % Clue 14 Soft_drink #= 2, % Clue 15 neighbors(Riley,Tie), % Clue 16 between2(Water,Age_23,Age_50), % Clue 17 right_neighbor(Black,Jason), % Clue 18 neighbors(Cody,Soft_drink), % Clue 19 somewhereLeft(Blue,Sales), % Clue 20 IT #= Notepad, % Clue 21 Tea #= 3, % Clue 22 Chocolate #= HR, % Clue 23 Tie #= Green, % Clue 24 Vars = Names ++ Colors ++ Gifts ++ Department ++ Ages ++ Drinks, solve(Vars), foreach(I in 0..N-1) nth(Name,Names,I), nth(C,Colors,I), nth(G,Gifts,I), nth(Dep,Department,I), nth(A,Ages,I), nth(D,Drinks,I), printf("%-8w %-6w %-10w %-10w %-4w %-8w\n",NamesS[Name],ColorsS[C],GiftS[G],DepartmentS[Dep],AgesS[A],DrinksS[D]) end, fail, nl. go => true. right_neighbor(X,Y) => X+1 #= Y. left_neighbor(X,Y) => Y+1 #= X. neighbors(X,Y) => abs(X-Y) #= 1. % X+1 #= Y #\/ Y+1 #= X. between2(X,Y,Z) => (X+1#=Y #\/ X+2#=Y #\/ X+3#=Y) #/\ ( Y+1#=Z #\/ Y+2#=Z #\/ Y+3#=Z). somewhereLeft(X,Y) => X+1#=Y #\/ X+2#=Y #\/ X+3#=Y #\/ X+4#=Y.