% ex.pl % some example predicates that will help with assignment # 9 % remove an element (which much be present) from a list... remove(X,[X|R],R). remove(X,[F|R],[F|S]) :- remove(X,R,S). % generates permutations of the first input's list perm([X|Y],Z) :- perm(Y,W), remove(X,Z,W). perm([],[]). % checks if the input list is sorted sorted( [] ). 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). % splits the first argument's list into subsets, i.e., % sublists in which the order of elements may vary split( List, A, B ) :- perm( List, L2 ), append( A, B, L2 ).