/* "It's a tie" problem (Dell Logic Puzzles, October 1999) in Picat. From http://socrates.bmcc.cuny.edu/jsamuels/text/mhh-discrete-03ext.pdf """ Four colleagues recently got into a discussion about some of the flamboyant patterns showing up on neckties these days. As a joke, each man arrived at work the next day sporting the most ridiculous tie he could find (no two men wore ties with the same pattern—one tie was decorated with smiling cupids). None of the men had to venture outside of his own closet, as each had received at least one such tie from a different relative! From the following clues, can you match each man with the pattern on his flamboyant tie, as well as determine the relative who presented each man with his tie? (a) The tie with the grinning leprechauns wasn't a present from a daughter. (b) Mr. Crow’s tie features neither the dancing reindeer nor the yellow happy faces. (c) Mr. Speigler’s tie wasn’t a present from his uncle. (d) The tie with the yellow happy faces wasn’t a gift from a sister. (e) Mr. Evans and Mr. Speigler own the tie with the grinning leprechauns and the tie that was a present from a father-in-law, in some order. (f) Mr. Hurley received his flamboyant tie from his sister. """ 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, Mr = [Crow, Evans, Hurley, Speigler], Mr = 1..N, MrStr = ["Crow", "Evans", "Hurley", "Speigler"], Ties = [_Cupids, HappyFaces, Leprechauns, Reindeer], Ties :: 1..N, TiesStr = ["cupids", "happy_faces", "leprechauns", "reindeer"], TiesInv = new_list(N), TiesInv :: 1..N, Relative = [Daughter, FatherInLaw, Sister, Uncle], Relative :: 1..N, RelativeStr = ["daughter", "father-in-law", "sister", "uncle"], RelativeInv = new_list(N), RelativeInv :: 1..N, all_different(Ties), all_different(Relative), assignment(Ties, TiesInv), assignment(Relative, RelativeInv), % 1. The tie with the grinning leprechauns wasn't a present from a daughter. Leprechauns #!= Daughter, % 2. Mr. Crow's tie features neither the dancing reindeer nor the yellow happy faces. Crow #!= Reindeer, Crow #!= HappyFaces, % 3. Mr. Speigler's tie wasn't a present from his uncle. Speigler #!= Uncle, % 4. The tie with the yellow happy faces wasn't a gift from a sister. HappyFaces #!= Sister, % 5. Mr Evans and Mr. Speigler own the tie with the grinning leprechauns % and the tie that was a present from a father-in-law, in some order. ( (Evans #= Leprechauns #/\ Speigler #= FatherInLaw) #\/ (Speigler #= Leprechauns #/\ Evans #= FatherInLaw) ), % 6. Mr. Hurley received his flamboyant tie from his sister. Hurley #= Sister, Vars = Ties ++ TiesInv ++ Relative ++ RelativeInv, solve(Vars), % println(mr_str=MrStr), % println(ties=Ties), % println(tiesInv=TiesInv), % println(ties=[TiesStr[I] : I in TiesInv]), % println(relative=Relative), % println(relativeInv=RelativeInv), % println(ties=[RelativeStr[I] : I in RelativeInv]), % nl, foreach(I in 1..N) printf("Mr %w got the %w from his %w\n", MrStr[I], TiesStr[TiesInv[I]], RelativeStr[RelativeInv[I]]) end, fail, nl. go => true.