Guest User

Untitled

a guest
May 17th, 2012
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. prolog Searching the Lists
  2. predicate([a,c,b,d,e],[a,b,c,d]).
  3.  
  4. predicate([a,c,b,e,d],[a,b,c,d]).
  5.  
  6. has_prefix_perm(List1, List2) :-
  7. permutation(List2, Permutation),
  8. prefix(Permutation, List1),
  9. !.
  10.  
  11. has_prefix_perm(_, []) :- !.
  12. has_prefix_perm([Head1|List1], List2) :-
  13. once(select(Head1, List2, Rest)),
  14. has_prefix_perm(List1, Rest).
  15.  
  16. has_prefix_perm(List1, List2) :-
  17. length(List2, L),
  18. length(LittleL1, L),
  19. append(LittleL1, _, List1),
  20. permutation(LittleL1, List2),
  21. !.
  22.  
  23. perm_prefix(Ls1, Ls2) :- phrase(perm(Ls2), Ls1, _).
  24.  
  25. perm([]) --> [].
  26. perm(Ls0) --> [L], { select(L, Ls0, Ls1) }, perm(Ls1).
  27.  
  28. ?- perm_prefix([a,c,b,d,e],[a,b,c,d]).
  29. true
  30.  
  31. ?- perm_prefix([a,c,b,e,d],[a,b,c,d]).
  32. false.
Advertisement
Add Comment
Please, Sign In to add comment