/* Email communication puzzle in Picat. From Chris Smith's Math Newsletter #573 """ Seven people (Adam, Bill, Chris, Daisy, Elaine, Fay, and Guney) communicate with each other through email. Last week, each of them sent an email to three other people. It so happened that none of them received an email from the person to which they sent one. • Adam sent emails to Chris, Elaine, and Guney. • Bill sent emails to Daisy and Fay. • Chris sent an email to Elaine. • Daisy sent emails to Chris and Fay. • Elaine sent an email to Fay. Based on this information, can you complete the list above to show who received an email from whom """ This model 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 = 7, % number of people M = 3, % number of send email L = 1..N, [Adam, Bill, Chris, Daisy, Elaine, Fay, Guney] = L, S = ["Adam", "Bill", "Chris", "Daisy", "Elaine", "Fay", "Guney"], X = new_array(N,N), X :: 0..1, XT = X.transpose(), foreach(P in 1..N) sum(X[P]) #= M, % hakank: This is not stated explicitly: % each person received exactly 3 mail as well. sum(XT[P]) #= M end, % It so happened that none of them received an email from the person % to which they sent one. foreach(P1 in 1..N, P2 in P1+1..N) X[P1,P2] #= 1 #=> X[P2,P1] #= 0, X[P2,P1] #= 1 #=> X[P1,P2] #= 0 end, % • Adam sent emails to Chris, Elaine, and Guney. foreach(P in [Chris, Elaine, Guney]) X[Adam,P] #= 1 end, % • Bill sent emails to Daisy and Fay. foreach(P in [Daisy, Fay]) X[Bill,P] #= 1 end, % • Chris sent an email to Elaine. X[Chris,Elaine] #= 1, % • Daisy sent emails to Chris and Fay. foreach(P in [Chris, Fay]) X[Daisy,P] #= 1 end, % • Elaine sent an email to Fay. X[Elaine,Fay] #= 1, solve(X), foreach(Row in X) println(Row) end, nl, foreach(I in 1..N) printf("%-6s sent email to: ", S[I]), foreach(J in 1..N) if X[I,J] == 1 then print(S[J]), print(" ") end end, nl end, nl, fail, nl. go => true.