Last active
August 29, 2015 14:03
-
-
Save kuanyui/990903bd5f0ea941f7a2 to your computer and use it in GitHub Desktop.
Ugly and dumb solution for fucking run-length homework in PG's ACL.
This file contains hidden or 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 run-length (input) | |
(let (l fin) | |
(mapcar (lambda (x) | |
(if (null x) | |
(setq x "nil")) | |
(cond ((null l) | |
(setq fin (list (list 1 x))) | |
(setq l x)) | |
((equal x l) | |
(setq fin (cons (list (1+ (car (car fin))) x) (cdr fin)))) | |
(t | |
(setq fin (cons (list 1 x) fin)) | |
(setq l x)))) | |
input) | |
(reverse | |
(mapcar (lambda (x) | |
(if (eq (car x) 1) | |
(cadr x) | |
x)) | |
fin)))) | |
;; (run-length '(a a a b c c c c c d e e)) | |
;; => ((3 a) b (5 c) d (2 e)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment