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.
(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.
Note: These solutions are untested. Testing them is left as an exercise for you.