/*
Defending the Castle puzzle in Picat.
From http://www.cut-the-knot.org/do_you_know/lin_pr.shtml
"""
Assume that we have decided to position defenders of a square castle according to the following plan:
p q p
q 0 q
p q p
so that the total number of defenders is 4(p+q) while (2p+q) fighters face
the enemy on every side. Let's denote p = x1 and q = x2. Let also A = (4 4),
be a 1x2 matrix, and c = (2 1), a 1x2 row vector. Assume that a 1x1 vector
b is equal to (28). The linear programming problem (P) is then interpreted
as:
How to position 28 fighters according to the symmetric arrangement above
so as to have the maximum number of defenders on each side?
"""
This Picat 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 =>
P :: 0..100,
Q :: 0..100,
Z #= 2*P + Q,
4*(P + Q) #= 28,
Q #>= P,
solve($[max(Z)],[P,Q,Z]),
println([p=P,q=Q,z=Z]),
printf("%d %d %d\n", P,Q,P),
printf("%d %d %d\n", Q,0,Q),
printf("%d %d %d\n", P,Q,P),
nl.