Last active
August 29, 2015 14:07
-
-
Save adamrobbie/4e14dba97e59adf2f2c9 to your computer and use it in GitHub Desktop.
Revisions
-
adamrobbie revised this gist
Sep 29, 2014 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,10 +1,10 @@ defmodule RunLength do def run(string) do compress(String.slice(string, 1..-1), String.slice(string, 0, 1), 1, "") end defp compress("", char, count, result) do result <> Integer.to_string(count) <> char end defp compress(string, char, count, result) do @@ -16,7 +16,7 @@ defmodule RunLength do String.slice(string, 1..-1), next, 1, result <> Integer.to_string(count) <> char ) end end -
adamrobbie revised this gist
Sep 29, 2014 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -3,12 +3,12 @@ defmodule RunLength do compress(String.slice(string, 1..-1), String.slice(string, 0, 1), 1, []) end defp compress("", char, count, result) do result ++ [Integer.to_string(count) <> char] end defp compress(string, char, count, result) do next = String.slice(string, 0, 1) if next == char do compress(String.slice(string, 1..-1), char, count+1, result) else -
adamrobbie created this gist
Sep 29, 2014 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,23 @@ defmodule RunLength do def run(string) do compress(String.slice(string, 1..-1), String.slice(string, 0, 1), 1, []) end defp compress([], char, count, result) do result ++ [Integer.to_string(count) <> char] end defp compress(string, char, count, result) do next = String.slice(string, 1, 1) if next == char do compress(String.slice(string, 1..-1), char, count+1, result) else compress( String.slice(string, 1..-1), next, 1, result ++ [Integer.to_string(count) <> char] ) end end end