% ex.pl % some example predicates that may help with assignment # 4 % remove an element (which much be present) from a list... removeOne(X,[X|R],R). removeOne(X,[F|R],[F|S]) :- removeOne(X,R,S). % generates permutations of the first input's list perm([X|Y],Z) :- perm(Y,W), removeOne(X,Z,W). perm([],[]). % checks if the input list is sorted sorted( [] ). % zero-element lists are sorted. sorted( [_] ). % one-element lists are sorted sorted( [F,S|R] ) :- sorted( [S|R] ), F < S. % binds the second argument to a sorted version of the first mysort( [], [] ). mysort( L, S ) :- perm( L, S ), sorted(S). % inefficient!