/*
5x5 puzzle in Picat.
From Martin Chlond Integer Programming Puzzles:
http://www.chlond.demon.co.uk/puzzles/puzzles1.html, puzzle nr. 11.
Description : 5 X 5 puzzle
Source : Unknown
This model was inspired by the XPress Mosel model created by Martin Chlond.
http://www.chlond.demon.co.uk/puzzles/sol1s11.html
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,
X = new_array(N,N),
X :: 0..1,
D = new_array(N,N),
D :: 0..10000,
Moves #= sum([X[I,J] : I in 1..N, J in 1..N]),
foreach(I in 1..N, J in 1..N)
sum([X[I,K] : K in J-1..J+1, K >= 1, K <= N, K != J]) +
sum([X[K,J] : K in I-1..I+1, K >= 1, K <= N]) #= 2*D[I,J]+1
end,
solve($[min(Moves)], X.to_list() ++ D.to_list() ++ [Moves]),
writeln(moves=Moves),
foreach(Row in X) println(Row.to_list()) end,
nl.