Created
December 13, 2012 16:17
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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