%
% Fill-a-Pix problem in MiniZinc.
%
% From http://www.conceptispuzzles.com/index.aspx?uri=puzzle/fill-a-pix/basiclogic
% """
% Each puzzle consists of a grid containing clues in various places. The
% object is to reveal a hidden picture by painting the squares around each
% clue so that the number of painted squares, including the square with
% the clue, matches the value of the clue.
% """
%
% Other names of this puzzle:
%
% * Nurie-Puzzle
% * Majipiku
% * Oekaki-Pix
% * Mosaic
% * Mosaik
% * Mozaïek
% * ArtMosaico
% * Count and Darken
% * Nampre puzzle
% * Komsu Karala!
% * Cuenta Y Sombrea
% * Mosaico
% * Voisimage
% * Magipic
% * Fill-In
%
%
% http://www.conceptispuzzles.com/index.aspx?uri=puzzle/fill-a-pix/rules
% """
% Fill-a-Pix is a Minesweeper-like puzzle based on a grid with a pixilated
% picture hidden inside. Using logic alone, the solver determines which
% squares are painted and which should remain empty until the hidden picture
% is completely exposed.
% """
%
% Fill-a-pix History:
% http://www.conceptispuzzles.com/index.aspx?uri=puzzle/fill-a-pix/history
%
%
% This was created by Hakan Kjellerstrand, hakank@bonetmail.com
% See also http://www.hakank.org/answer_set_programming/
%
nums(0..9).
size(1..n).
% defining adjacency
adj(R,C,R1,C1) :- size(R;C;R1;C1), |R-R1| + |C-C1|==1.
adj(R,C,R1,C1) :- size(R;C;R1;C1), size(C1), |R-R1|==1, |C-C1|==1.
adj(R,C,R,C) :- size(R;C).
% N "mines" around a number N.
N { x(R2,C2) : adj(R2,C2,R1,C1) } N :- hint(R1,C1,N).
#hide.
#show x(R,C).