Created
July 16, 2020 11:50
-
-
Save dra1n/635e38a7eae827695a0cb51a3dc7cd7e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (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