/* "Einstein puzzle" in Picat. Translated from the LPL model in Tony Hurlimann "Mathematical Modelling of Puzzles and Games", page 181 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 = 5, A = new_list(N), % Nationalities: Norwegian, Dane, Briton, Swede, German A :: 1..N, B = new_list(N), % Colors: yellow blue red green white B :: 1..N, C = new_list(N), % Pets: cat bird dog horse fish C :: 1..N, D = new_list(N), % Drinks: coffee tea milk juice water D :: 1..N, E = new_list(N), % Smokes: Dunhill Marlboro Pall-Mall Bluemaster Prince E :: 1..N, Nationalities = ["Norwegian", "Dane", "Briton", "Swede", "German"], all_different(A), all_different(B), all_different(C), all_different(D), all_different(E), A[3] #= B[3], A[4] #= C[3], A[2] #= D[2], B[4] + 1 #= B[5], B[4] #= D[1], E[3] #= C[2], D[3] #= 3, B[1] #= E[1], A[1] #= 1, (E[2] #= C[1]+1 #\/ E[2] #= C[1]-1), (C[4] #= E[1]+1 #\/ C[4] #= E[1]-1), E[4] #= D[4], B[2] #= 2, A[5] #= E[5], (E[2] #= D[5] + 1 #\/ E[2] #= D[5] - 1), solve(A ++ B ++ C ++D ++ E), writeln(a=A), writeln(b=B), writeln(c=C), writeln(d=D), writeln(e=E), printf("The %w owns the fish.\n", Nationalities[A[C[5]]]), nl.