Advertisement
Guest User

Untitled

a guest
Apr 26th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Prolog 0.38 KB | None | 0 0
  1. % 1.08 (**): Eliminate consecutive duplicates of list elements.
  2.  
  3. % compress(L1,L2) :- the list L2 is obtained from the list L1 by
  4. %    compressing repeated occurrences of elements into a single copy
  5. %    of the element.
  6. %    (list,list) (+,?)
  7.  
  8. compress([],[]).
  9. compress([X],[X]).
  10. compress([X,X|Xs],Zs) :- compress([X|Xs],Zs).
  11. compress([X,Y|Ys],[X|Zs]) :- X \= Y, compress([Y|Ys],Zs).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement