Unique selection of the select/2
domain does the trick:
select([A|As],S):- select(A,S,S1),select(As,S1). select([],_). words(X) :- X = [ [a,b,a,n,d,o,n], [a,b,a,l,o,n,e], [a,n,a,g,r,a,m], [b,o,a,t], [b,o,a,t,m,a,n], [c,h,i,l,d], [c,o,n,n,e,c,t], [e,l,e,g,a,n,t], [e,n,h,a,n,c,e], [i,s,l,a,n,d], [m, a, n], [s,a,n,d], [s,u,n], [w, o, m, a, n] ]. solve(Crossword):- words(Words), Crossword = [ [_,A2,_,A4,_,A6,_], [_,B2,_,B4,_,B6,_], [_,C2,_,C4,_,C6,_], [_,A2,_,B2,_,C2,_], [_,A4,_,B4,_,C4,_], [_,A6,_,B6,_,C6,_] ], select(Crossword, Words). solve:- solve(Crossword), maplist(writeln, Crossword), writeln(';'), fail ; writeln('No more solutions!').
Test:
7 ?- solve. [a, b, a, n, d, o, n] [e, l, e, g, a, n, t] [e, n, h, a, n, c, e] [a, b, a, l, o, n, e] [a, n, a, g, r, a, m] [c, o, n, n, e, c, t] ; [a, b, a, l, o, n, e] [a, n, a, g, r, a, m] [c, o, n, n, e, c, t] [a, b, a, n, d, o, n] [e, l, e, g, a, n, t] [e, n, h, a, n, c, e] ; No more solutions!
This solution allows the use of unique words in the puzzle (duplication is not allowed). This may or may not be what you intended.