/* Blueberry Muffins problem in Picat. Problem description from http://brownbuffalo.sourceforge.net/BlueberryMuffinsClues.html """ Daniel made a dozen blueberry muffins on Friday night -- and by the time he was ready for brunch on Saturday, there were only two left. The other ten had been snitched by his housemates, all of whom had gotten up early because they had to work on Saturday. The four housemates include two men named Bill and Mark, and two women named Calla and Lynn; last names are Ellis, Ingham, Oakley, and Summers, and their differing professions are dogcatcher, flautist, secretary, and zookeeper. Can you discover each one's full name, profession, and number of muffins snitched? 1. Each housemate snitched a different number of muffins from one to four. 2. Bill and Ellis snitched a total of six muffins. 3. The secretary (who is a woman) snitched more than the dogcatcher. 4. Mark snitched two more than Summers did. 5. The flautist snitched twice as many as Ms. Oakley did. 6. Calla's last name isn't Ingham. Determine: First name -- Last name -- Job -- Muffins """ 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, Firstname = [Bill,Mark,Calla,Lynn], Firstname = 1..N, FirstnameS = [bill, mark, calla, lynn], Lastname = [Ellis, Ingham, Oakley, Summers], Lastname :: 1..4, LastnameS = [ellis, ingham, oakley, summers], Job = [Dogcatcher, Flautist, Secretary, _Zookeeper], Job :: 1..N, JobS = [dogcatcher, flautist, secretary, zookeeper], Muffins = new_list(N), Muffins :: 1..4, all_different(Lastname), all_different(Job), % 1. Each housemate snitched a different number of muffins from one to four. all_different(Muffins), % 2. Bill and Ellis snitched a total of six muffins. element(Ellis,Muffins,MuffinsEllis), Muffins[Bill] + MuffinsEllis #= 6 , Ellis #!= Bill, % 3. The secretary (who is a woman) snitched more than the dogcatcher. (Secretary #= Calla #\/ Secretary #= Lynn), element(Secretary,Muffins,MuffinsSecretary), element(Dogcatcher,Muffins,MuffinsDogcatcher), MuffinsSecretary #> MuffinsDogcatcher, % 4. Mark snitched two more than Summers did. element(Summers,Muffins,MuffinsSummers), Muffins[Mark] #= MuffinsSummers + 2, Summers #!= Mark, % 5. The flautist snitched twice as many as Ms. Oakley did. element(Flautist,Muffins,MuffinsFlautist), element(Oakley,Muffins,MuffinsOakley), MuffinsFlautist #= MuffinsOakley * 2, Flautist #!= Oakley, (Oakley #= Calla #\/ Oakley #= Lynn), % 6. Calla's last name isn't Ingham. Ingham #!= Calla, Vars = Lastname ++ Job ++ Muffins, solve(Vars), println(lastName=Lastname), println(job=Job), println(muffins=Muffins), nl, foreach(I in 1..N) nth(LN,Lastname,I), nth(J,Job,I), println([FirstnameS[I],LastnameS[LN],JobS[J],Muffins[I]]) end, nl, fail, nl. go => true.