My solutions to https://www.ic.unicamp.br/~meidanis/courses/mc336/problemas-lisp/L-99_Ninety-Nine_Lisp_Problems.html

Solve P11, Modified RLE

Changed files
+13
+13
99problems.lisp
··· 114 114 (setq res (append res (cons (list (length sl) (car sl)) nil)))))) 115 115 116 116 (print (rle (pack '(a a a a b c c a a d e e e e)))) 117 + 118 + ;; P11: Modified RLE 119 + ;; Modify the result of problem P10 in such a way that if an element has no duplicates it is simply copied into the result list. 120 + ;; Only elements with duplicates are transferred as (N E) lists. 121 + 122 + (defun rle2 (lst) 123 + (let ((res nil)) 124 + (dolist (sl lst res) 125 + (setq res (append res (if (null (cdr sl)) 126 + (cons (car sl) nil) 127 + (cons (list (length sl) (car sl)) nil))))))) 128 + 129 + (print (rle2 (pack '(a a a a b c c a a d e e e e)))) ;; ((4 A) B (2 C) (2 A) D (4 E))