Skip to content

Instantly share code, notes, and snippets.

@sordina
Created June 4, 2018 01:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sordina/3f8a07b7835a16a9110614718df52865 to your computer and use it in GitHub Desktop.
Save sordina/3f8a07b7835a16a9110614718df52865 to your computer and use it in GitHub Desktop.
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