Created
February 4, 2021 13:01
-
-
Save ahamez/617a9dbcbe861d17fdc2f00065d72cac to your computer and use it in GitHub Desktop.
RLE
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
# As an exercise after reading this tweet: https://twitter.com/Al_Grigor/status/1357028887209902088?s=20 | |
str = String.split("aaaabbbcca", "", trim: true) | |
str | |
|> Enum.reduce([], fn | |
x, [{x, count} | rest] -> | |
[{x, count + 1} | rest] | |
x, acc -> | |
[{x, 1} | acc] | |
end) | |
|> Enum.reverse() | |
|> IO.inspect() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment