Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Prolog 0.83 KB | None | 0 0
  1. mem(H, [H|_]).
  2. mem(X, [_|T]) :- mem(X, T).
  3.  
  4. mem2(H, [H|_]) :- !.
  5. mem2(X, [_|T]) :- mem2(X, T).
  6.  
  7. remove(H, [H|T], T).
  8. remove(X, [H|T], [H|Z]) :- remove(X, T, Z).
  9.  
  10. remove2(H, [H|T], T) :- !.
  11. remove2(X, [H|T], [H|Z]) :- remove2(X, T, Z).
  12.  
  13. removeAll(_, [ ], [ ]).
  14. removeAll(H, [H|T], Z) :- removeAll(H, T, Z).
  15. removeAll(X, [H|T], [H|Z]) :- not(X=H), removeAll(X, T, Z).
  16.  
  17. permute([ ], [ ]).
  18. permute(L, [H|T]) :- member(H, L), remove(H, L, Z), permute(Z, T).
  19.  
  20. ascend([ ]).
  21. ascend([_]).
  22. ascend([A,B|T]) :- A =< B, ascend([B|T]).
  23.  
  24. perm_sort(L, R) :- permute(L, R), ascend(R).
  25.  
  26. tree1([h, [d, [b, [a], [c]], [f, [e], [g]]], [n, [k, [j], [m]], [q, [p], [r]]]]).
  27.  
  28. postorder([X], [X]).
  29. postorder([X, L, R], Z) :-  postorder(L, A), postorder(R, B),
  30.                             append(B, [X], C), append(A, C, Z).
  31.  
  32.  
  33. not(X) :- \+ X.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement