/* Lights on puzzle in Picat. From Martin Chlond Integer Programming Puzzles: http://www.chlond.demon.co.uk/puzzles/puzzles1.html, puzzle nr. 12. Description : Lights on puzzle Source : Unknown This model was inspired by the XPress Mosel model created by Martin Chlond. http://www.chlond.demon.co.uk/puzzles/sol1s12.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 = 4, R = [[0, 1, 0, 0], [1, 0, 1, 0], [1, 1, 0, 0], [0, 1, 1, 1]], % decision variables X = new_array(N,N), X :: 0..1, D = new_array(N,N), foreach(I in 1..N, J in 1..N) X[I,J] #>= 0 end, Moves #= sum(X.vars()), foreach(I in 1..N, J in 1..N) sum([(X[I,L]) : L in 1..N]) + sum([X[K,J] : K in 1..N, K != I]) #= 2*D[I,J]+R[I,J] end, solve($[min(Moves)], X ++ D), println(moves=Moves), print_matrix("X:", X), print_matrix("D:", D), nl. print_matrix(Name,X) => println(Name), foreach(Row in X) println(Row.to_list()) end, nl.