Skip to content

Instantly share code, notes, and snippets.

@ghisguth
Last active April 4, 2017 09:34
Show Gist options
  • Save ghisguth/04ea34a52205b372636d5fba976ab26f to your computer and use it in GitHub Desktop.
Save ghisguth/04ea34a52205b372636d5fba976ab26f to your computer and use it in GitHub Desktop.
(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