Last active
September 8, 2015 13:15
-
-
Save v-kolesnikov/aa0caa586dffbb2d4891 to your computer and use it in GitHub Desktop.
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
; remove duplicates from sequence | |
; third | |
(defn compress [seq] | |
(->> seq | |
(reduce #(cond | |
(= %2 (first %1)) %1 | |
:else (conj %1 %2)) | |
nil) | |
(reverse))) | |
; vs second | |
(defn compress [seq] | |
(loop [head [] tail seq] | |
(cond | |
(nil? tail) nil | |
(nil? (second tail)) (concat head tail) | |
(= (first tail) | |
(first (rest tail))) (recur head (rest tail)) | |
:else (recur (conj head | |
(first tail)) | |
(rest tail))))) | |
; vs first | |
(defn compress_ [seq] | |
(cond | |
(nil? seq) nil | |
(nil? (second seq)) seq | |
(= (first seq) | |
(first (rest seq))) (compress_ (rest seq)) | |
:else (cons (first seq) | |
(compress_ (rest seq))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment