%% search.pl start([]). goal(S) :- length(S,8). next_state(S,[C|S]) :- member(C,[1,2,3,4,5,6,7,8]), not member(C,S). safe_state([C|S]) :- length(S,L), Sum is C+L+1, Diff is C-L-1, safe_state(S,Sum,Diff). safe_state([],_,_) :- !. safe_state([F|R],Sm,Df) :- length(R,L), X is F+L+1, X \= Sm, Y is F-L-1, Y \= Df, safe_state(R,Sm,Df).