Anonymous user
Run-length encoding: Difference between revisions
Emacs Lisp: Completely rewrite solutions to something readable
(Emacs Lisp: Completely rewrite solutions to something readable) |
|||
Line 2,286:
=={{header|Emacs Lisp}}==
<lang lisp>(defun run-length-encode (str)
(let (output)
(defun run-length-encode (str_arg)▼
(with-temp-buffer
(insert str)
(goto-char (point-min))
(while (not (eobp))
(let* ((char (char-after (point)))
(count (skip-chars-forward (string char))))
(push (format "%c%d" char count) output))))
(mapconcat #'identity (nreverse output) "")))</lang>
{{libheader|seq.el}}
<lang lisp>(require 'seq)
(let ((grouped (mapcar #'cdr (seq-group-by #'identity (string-to-list str)))))
(apply #'concat (mapcar (lambda (items)
(format "%c%d" (car items) (length items)))
grouped))))</lang>
=={{header|Erlang}}==
|