Created
October 20, 2014 17:32
-
-
Save robmerrell/568743555781c57c76ba to your computer and use it in GitHub Desktop.
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
defmodule ListSubset do | |
defp _contains_letters_count([], _, acc), do: acc | |
defp _contains_letters_count([h|t], compare, acc) do | |
new_list = List.delete(compare, h) | |
diff = length(compare) - length(new_list) | |
_contains_letters_count(t, new_list, acc+diff) | |
end | |
def is_subset(str1, str2) do | |
count = _contains_letters_count(str1, str2, 0) | |
count == length(str2) | |
end | |
end | |
ListSubset.is_subset('hello', 'leoh') # true | |
ListSubset.is_subset('hello', 'leohh') # false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment