Created
June 4, 2018 01:15
-
-
Save sordina/3f8a07b7835a16a9110614718df52865 to your computer and use it in GitHub Desktop.
This file contains 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
defmodule Looksay do | |
def build([h|l]) do | |
n = l |> length |> Looksay.succ |> inspect | |
n <> h | |
end | |
def succ(x), do: x + 1 | |
def group([],x), do: [ x ] | |
def group([h|t],[]), do: group(t,[h]) | |
def group([h|t2],[h|t1]), do: group(t2,[h|[h|t1]]) | |
def group([h|t2],[g|t1]), do: [ [g|t1] | group([h|t2], []) ] | |
def main(args) do | |
args | |
|> Enum.map( | |
fn y | |
-> y | |
|> String.split("", trim: true) | |
|> Looksay.group([]) | |
|> Enum.map( &( Looksay.build(&1) ) ) | |
|> Enum.reduce("", &(&2 <> &1)) | |
|> IO.puts | |
end ) | |
:ok | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment