/* Twelve draughts puzzle in Picat. From Martin Chlond Integer Programming Puzzles: http://www.chlond.demon.co.uk/puzzles/puzzles1.html, puzzle nr. 1. Description : Twelve draughts puzzle Source : Boris Kordemsky - The Moscow Puzzles (P36) """ Twelve draught pieces are arranged in a square frame with four on each side. Try placing them so there are 5 on each side. (Kordemsky) Maybe this problem is not described very well but I wanted to stick with the original text from Kordemsky. The problem may be stated in terms of guards on the wall of a square fort. If a guard stands on a side wall then he may only watch that particular wall whereas a guard at a corner may watch two walls. If twelve guards are positioned such that there are two on each side wall and one at each corner then there are four guards watching each wall. How can they be rearranged such that there are five watching each wall? """ This model was inspired by the XPress Mosel model created by Martin Chlond. http://www.chlond.demon.co.uk/puzzles/sol1s1.html There is 416 different solutions to this problem. 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 => S = 4, X = new_array(S,S), X :: 0..10, % total of 12 pieces placed sum([X[I,J] : I in 1..S, J in 1..S]) #= 12, % 5 pieces on each side sum([X[1,J] : J in 1..S]) #= 5, sum([X[I,1] : I in 1..S]) #= 5, sum([X[4,J] : J in 1..S]) #= 5, sum([X[I,4] : I in 1..S]) #= 5, % inner squares unused sum([X[I,J] : I in 2..3, J in 2..3]) #= 0, solve(X), println("X:"), foreach(Row in X) println(Row.to_list()) end, nl.