|
Create a four by four table with a one representing each red square and a zero
representing each white square.
Without touching the puzzle, figure out what the new configuration would be if
you had clicked every red square. Create a second table, as above, based on this
configuration.
Add the two tables, element by element, into a third table.
The cells in the third table that contain the number one are the cells to click
in order to complete the puzzle in the minimum number of moves.
model 'lights'
! Description : Lights on puzzle
! Source : Unknown
! Date written : Xpress-MP 5/4/97, Mosel 17/4/03
! Written by : M J Chlond
uses 'mmxprs'
parameters
n = 4
end-parameters
declarations
N = 1..n
r: array(N,N) of real
x: array(N,N) of mpvar
d: array(N,N) of mpvar
end-declarations
r:= [0,1,0,0,
1,0,1,0,
1,1,0,0,
0,1,1,1]
moves:= sum(i in N, j in N) x(i,j)
forall(i in N, j in N)
con(i,j):= sum(l in N) x(i,l) +
sum(k in N | k <> i) x(k,j) = 2*d(i,j)+r(i,j)
forall(i in N, j in N) do
x(i,j) is_binary
d(i,j) is_integer
end-do
minimise(moves)
forall(i in N) do
forall(j in N)
write(getsol(x(i,j)),' ')
writeln
end-do
end-model
|