Skip to content

Instantly share code, notes, and snippets.

@dra1n
Created July 16, 2020 11:50
Show Gist options
  • Select an option

  • Save dra1n/635e38a7eae827695a0cb51a3dc7cd7e to your computer and use it in GitHub Desktop.

Select an option

Save dra1n/635e38a7eae827695a0cb51a3dc7cd7e to your computer and use it in GitHub Desktop.
(defn rle
[s]
(->> s
(partition-by identity)
(map #((juxt first count) %))))
(defn rld
[pairs]
(->> pairs
(map (fn [[k v]] (clojure.string/join (repeat v k))))
(clojure.string/join)))
(rld (rle "WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWW"))
# "WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWW"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment