Skip to content

Instantly share code, notes, and snippets.

@trietptm
Created December 13, 2012 16:17
Show Gist options
  • Save trietptm/4277556 to your computer and use it in GitHub Desktop.
Save trietptm/4277556 to your computer and use it in GitHub Desktop.
Eliminate consecutive duplicates of list elements. If a list contains repeated elements they should be replaced with a single copy of the element. The order of the elements should not be changed.
compress([X|[]], [X]).
compress([X|[X|Z]], L) :- compress([X|Z], L),!.
compress([X|[Y|Z]], [X|L]) :- compress([Y|Z], L),!.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment