goal([2/2, 1/1, 1/2, 2/1]). goal([3/3, 1/1, 1/2, 1/3, 2/1, 2/2, 2/3, 3/1, 3/2]). goal([4/4, 1/1, 1/2, 1/3, 1/4, 2/1, 2/2, 2/3, 2/4, 3/1, 3/2, 3/3, 3/4, 4/1, 4/2, 4/3]). %goal([X/X|Rest]) :- % L is X*X-1, % length(Rest, L), % sort(Rest, Rest). solve(A, Solution) :- between(1, 25, I), solve(A, [A], I, Solution), !. solve(_, _, 0, _) :- !, fail. solve(State, Solution, _, Solution) :- goal(State), !. solve(State, Visisted, D, Solution) :- succesor(State, NextState), \+ member(NextState, Visisted), D1 is D-1, solve(NextState, [NextState|Visisted], D1, Solution).