Skip to content

Instantly share code, notes, and snippets.

@robmerrell
Created October 20, 2014 17:32
Show Gist options
  • Save robmerrell/568743555781c57c76ba to your computer and use it in GitHub Desktop.
Save robmerrell/568743555781c57c76ba to your computer and use it in GitHub Desktop.
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