Skip to content

Instantly share code, notes, and snippets.

View jsmesami's full-sized avatar

Ondřej Nejedlý jsmesami

  • Prague
View GitHub Profile

Run-length encode a sequence

Run-length encoding is a way to represent a sequence in a more compact form. Instead of saying :p :p :p, you say “3 :ps”. Write a function that takes a sequence and returns that sequence with run-length encoding.

For example:

(rle [:a :a :a :b :c :d :d :d :d])
;=> ([3 :a] [1 :b] [1 :c] [4 :d])