asb: head /dev/brain > /dev/www

My home, musings, and wanderings on the world wide web.

99 LISP problems: Problem #12

Solution to the 99 LISP Problems #12

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
(defun decompress-one (n elem)
  (if (<= n 0)
    nil
    (append
      (list elem)
      (decompress-one (1- n) elem))))

(defun decode-rle (encoding)
  (if (null encoding)
    nil
    (append
      (if (listp (car encoding))
        (decompress-one (caar encoding) (second (car encoding)))
        (list (car encoding)))
      (decode-rle (cdr encoding)))))

Lisp dialect: Steel Bank Common Lisp