/* Ships puzzle in Picat. From Adrian Groza "Modelling Puzzles in First Order Logic" See https://www.researchgate.net/publication/374588335_Measuring_reasoning_capabilities_of_ChatGPT """ Puzzle 50. Ships There are five ships in a port: 1. The Greek ship leaves at six and carries coffee. 2. The Ship in the middle has a black exterior. 3. The English ship leaves at nine. 4. The French ship with blue exterior is to the left of a ship that carries coffee. 5. To the right of the ship carrying cocoa is a ship going to Marseille. 6. The Brazilian ship is heading for Manila. 7. Next to the ship carrying rice is a ship with a green exterior. 8. A ship going to Genoa leaves at five. 9. The Spanish ship leaves at 7 and is to the right of the ship going to Marseille. 10. The ship with a red exterior goes to Hamburg. 11. Next to the ship leaving at seven is a ship with a white exterior. 12. The ship on the border carries corn. 13. The ship with a black exterior leaves at eight. 14. The ship carrying corn is anchored next to the ship carrying rice. 15. The ship to Hamburg leaves at six. Which ship goes to Port Said? Which ship carries tea? (taken from Math is fun— www.mathisfun.com) """ Solution: Country Time Carry Color Heading ------------------------------------------ French 05:00 Tea Blue Genoa Greek 06:00 Coffee Red Hamburg Brazilian 08:00 Cocoa Black Manila English 09:00 Rice White Marseille Spanish 07:00 Corn Green Port Said 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 => N = 5, Nationalities = new_list(N), Nationalities :: 1..N, [Greek,English,French,Brazilian,Spanish] = Nationalities, ["Greek","English","French","Brazilian","Spanish"] = NationalitiesS, LeavesAt = new_list(N), LeavesAt :: 1..5, [Five,Six,Seven,Eight,Nine] = LeavesAt, ["05:00","06:00","07:00","08:00","09:00"] = LeavesAtS, Carrying = new_list(N), Carrying :: 1..N, [Coffee,Cocoa,Rice,Corn,_Tea] = Carrying, ["Coffee","Cocoa","Rice","Corn","Tea"] = CarryingS, Color = new_list(N), Color :: 1..N, [Black,Blue,Green,Red,White] = Color, ["Black","Blue","Green","Red","White"] = ColorS, Heading = new_list(N), Heading :: 1..N, [Marseille,Manila,Genoa,Hamburg,_PortSaid] = Heading, ["Marseille","Manila","Genoa","Hamburg","Port Said"] = HeadingS, all_different(Nationalities), all_different(LeavesAt), all_different(Carrying), all_different(Color), all_different(Heading), % 1. The Greek ship leaves at six and carries coffee. Greek #= Coffee, Greek #= Six, % 2. The Ship in the middle has a black exterior. Black #= 3, % 3. The English ship leaves at nine. English #= Nine, % 4. The French ship with blue exterior is to the left of a ship that carries coffee. French #= Blue, French + 1 #= Coffee, % 5. To the right of the ship carrying cocoa is a ship going to Marseille. Marseille #= Cocoa + 1, % 6. The Brazilian ship is heading for Manila. Brazilian #= Manila, % 7. Next to the ship carrying rice is a ship with a green exterior. abs(Rice-Green) #= 1, % 8. A ship going to Genoa leaves at five. Genoa #= Five, % 9. The Spanish ship leaves at 7 and is to the right of the ship going to Marseille. Spanish #= Seven, Marseille + 1 #= Spanish, % 10. The ship with a red exterior goes to Hamburg. Red #= Hamburg, % 11. Next to the ship leaving at seven is a ship with a white exterior. abs(Seven-White) #= 1, % 12. The ship on the border carries corn. Corn #= 1 #\/ Corn #= 5, % 13. The ship with a black exterior leaves at eight. Black #= Eight, % 14. The ship carrying corn is anchored next to the ship carrying rice. abs(Corn-Rice) #= 1, % 15. The ship to Hamburg leaves at six. Hamburg #= Six, % Which ship goes to Port Said? Which ship carries tea? (taken from Math is fun— % www.mathisfun.com) Vars = Nationalities++LeavesAt++Carrying++Color++Heading, solve(Vars), % println(nationalities=Nationalities), % println("leavesAt "=LeavesAt), % println("carrying "=Carrying), % println("color "=Color), % println("heading "=Heading), println("Country Time Carry Color Heading"), println("------------------------------------------"), foreach(I in 1..N) nth(Nat,Nationalities,I), nth(At,LeavesAt,I), nth(Carry,Carrying,I), nth(Col,Color,I), nth(Head,Heading,I), printf("%-9s %-5s %-7s %-6s %-9s\n", NationalitiesS[Nat],LeavesAtS[At],CarryingS[Carry],ColorS[Col],HeadingS[Head]) end, fail, nl.