Last active
April 4, 2017 09:34
-
-
Save ghisguth/04ea34a52205b372636d5fba976ab26f 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
(defun encode(input) | |
(defun enc(out cur cnt inp) | |
(defun flush() (cons cnt (cons cur out))) | |
(cond | |
((null inp) (if (null cur) out (flush))) | |
((null cur) (enc out (car inp) 1 (cdr inp))) | |
((eq cur (car inp)) (enc out cur (+ cnt 1) (cdr inp))) | |
(t (enc (flush) (car inp) 1 (cdr inp))))) | |
(nreverse (enc '() '() '() input))) | |
(defun test(input) | |
(format t "~a => ~a~%" input (encode input))) | |
(test '(a b b b c)) | |
(test '(a b)) | |
(test '()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment