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])
Then, write a function to decode the run-length representation.
(rld '([3 :a] [1 :b] [1 :c] [4 :d]))
;=> (:a :a :a :b :c :d :d :d :d)
That’s two functions: one to encode, and one to decode. Bonus points for laziness, concision, and efficiency.
https://purelyfunctional.tv/issues/purelyfunctional-tv-newsletter-317-when-you-see-a-job-apply/
Note: These solutions are untested. Testing them is left as an exercise for you.