anagram function with a set of words