/* Seating the party in Picat. From Adrian Groza "Modelling Puzzles in First Order Logic" """ Puzzle 59. Seating the party As the Crackham family were taking their seats on starting out on their tour, Dora asked in how many different ways they could all be seated, as there were six of them and six seats-one beside the driver, two with their backs to the driver, and two behind, facing the driver-if no two of the same sex are ever to sit side by side? As the Colonel, Uncle Jabez, and George were the only ones who could drive, it required just a little thinking out. Perhaps the reader will like to work out the answer concerning on which they all agreed at the end of the day. (puzzle 465 from Dudeney (2016)) """ Note: There is not explicit mention of the number of females. Groza assumes three men and three women, and so do I. The gender is encoded as - male: even numbers - female: odd numbers The (male) driver is in position [1,2] There are 144 solutions, e.g. [1,2] [3,4] [5,6] [1,2] [3,4] [6,5] [1,2] [3,6] [4,5] ... [5,6] [4,3] [1,2] [5,6] [4,3] [2,1] 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 ?=> seating_the_party(X), println(x=X), foreach(Row in X), println(Row.to_list) end, nl, fail, nl. go => true. /* Gender is encoded as male: even female: odd The driver is in position (1,2) */ seating_the_party(X) => N = 6, Rows = 3, Cols = 2, % Three 2 person seats X = new_array(Rows,Cols), X :: 1..N, all_different(X.vars), % Driver must be one of the three male X[1,2] mod 2 #= 0, foreach(I in 1..Rows) % Different gender on each 2 person seat X[I,1] mod 2 #!= X[I,2] mod 2 end, solve(X.vars).