Created
September 28, 2008 06:07
-
-
Save g000001/13415 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
(defn | |
#^{:doc "P11 (*) Modified run-length encoding." | |
:test (do (test= (encode-modified '(a a a a b c c a a d e e e e)) | |
'((4 a) b (2 c) (2 a) d (4 e))) | |
(test= (encode-modified []) []) | |
(test= (encode-modified [1]) [1]))} | |
; --------------- | |
encode-modified | |
; --------------- | |
([coll] | |
(if (empty? coll) | |
[] | |
(map #(if (single? %) | |
(first %) | |
(list (count %) (first %))) | |
(pack coll))))) | |
(defn single? [coll] | |
(nil? (rest coll))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment