#:g1: GOOでL-99 (P11 要素をランレングス圧縮する その2)

Posted 2008-04-12 00:13:00 GMT

-(http://www.ic.unicamp.br/~meidanis/courses/mc336/2006s2/funcional/L-99_Ninety-Nine_Lisp_Problems.html)
前回(P10)の内容をちょっと変更して終了

(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))
(encode-modified "aaaabccaadeeee")
;=> "4;a,b,2;c,2;a,d,4;e"

(dm encode-modified (u|<col> => <col>) (as (class-of u) (map (fun (x) (let ((xlen (len x))) (if (= 1 xlen) (head x) `(,xlen ,(head x))))) (my-pack1 u))))

(dm encode-modified (u|<str> => <str>) (join (map (fun (x) (let ((xlen (len x))) (cat (if (= 1 xlen) "" (cat (to-str xlen) ";")) (to-str (head x))))) (my-pack1 u)) ","))


comments powered by Disqus