Skip to content

Instantly share code, notes, and snippets.

@ahamez
Created February 4, 2021 13:01
Show Gist options
  • Save ahamez/617a9dbcbe861d17fdc2f00065d72cac to your computer and use it in GitHub Desktop.
Save ahamez/617a9dbcbe861d17fdc2f00065d72cac to your computer and use it in GitHub Desktop.
RLE
# 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