:- lib(ic).

minl([Only], Only).
minl([Head|Tail], Minimum) :-
    minl(Tail, TailMin),
    Minimum #= min(Head, TailMin). 

maxl([Only], Only).
maxl([Head|Tail], Max) :-
    maxl(Tail, TailMax),
    Max #=  max(Head, TailMax). 

noholes(L) :- length(L,Length),
              maxl(L,Max),minl(L,Min),Length #= Max-Min+1.

grille(L) :-
    L = [    X12,X13,  
             X22,X23,X24,X25,X26,
             X32,X33,X34,X35,X36,
         X41,X42,X43,X44,X45,
         X51,X52,X53,X54,X55,
                     X64,X65],
    L::[1..6],
    X25#=5,X33#=1,X41#=4,X52#=6,X53#=5,X65#=1,
    alldifferent([X12,X13,1]),
    alldifferent([X22,X23,X24,X25,X26]),
    alldifferent([X32,X33,X34,X35,X36]),
    alldifferent([X41,X42,X43,X44,X45]),
    alldifferent([X51,X52,X53,X54,X55]),
    alldifferent([X64,X65,4]),
    alldifferent([X41,X51]),
    alldifferent([X12,X22,X32,X42,X52]),
    alldifferent([X13,X23,X33,X43,X53]),
    alldifferent([1,X24,X34,X44,X54,X64]),
    alldifferent([X25,X35,X45,X55,X65]),
    alldifferent([X26,X36,4]),
    noholes([X12,X13]),
    noholes([X22,X23,X24,X25,X26]),
    noholes([X32,X33,X34,X35,X36]),
    noholes([X41,X42,X43,X44,X45]),
    noholes([X51,X52,X53,X54,X55]),
    noholes([X64,X65]),
    noholes([X41,X51]),
    noholes([X12,X22,X32,X42,X52]),
    noholes([X13,X23,X33,X43,X53]),
    noholes([X24,X34,X44,X54,X64]),
    noholes([X25,X35,X45,X55,X65]),
    noholes([X26,X36]).

    
