Last active
February 26, 2016 14:57
Revisions
-
unix1 revised this gist
Feb 26, 2016 . No changes.There are no files selected for viewing
-
unix1 created this gist
Feb 26, 2016 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,27 @@ (defun rle-encode (lst) (reverse (rle-lib-encode lst nil))) (defun rle-lib-encode (lst acc) (if (null lst) acc (let ((curr (car lst)) (prev (car acc)) (cnt (car (cdr acc)))) (if (equal curr prev) (rle-lib-encode (cdr lst) (cons curr (cons (+ cnt 1) (cdr (cdr acc))))) (rle-lib-encode (cdr lst) (cons curr (cons 1 acc))))))) (defun rle-decode (lst) (reverse (rle-lib-decode lst nil))) (defun rle-lib-decode (lst acc) (if (null lst) acc (let ((cnt (car lst)) (chr (car (cdr lst)))) (rle-lib-decode (cdr (cdr lst)) (rle-lib-seq chr cnt acc))))) (defun rle-lib-seq (chr cnt acc) (if (eql cnt 0) acc (rle-lib-seq chr (- cnt 1) (cons chr acc))))