Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Test whether strings are anagrams
ResourceFunction["AnagramQ"][s1,s2] yields True if s1 is an anagram of s2. | |
ResourceFunction["AnagramQ"][s1,s2,…] yields True if all the strings si are anagrams of one another. |
| IgnoreCase | True | treats lowercase and uppercase letters as equivalent. |
| IgnoreDiacritics | False | treats diacritics and regular letters as equivalent. |
| "IgnoreSpaces" | True | ignores spaces from the strings. |
Test whether "trace" is an anagram of "crate":
| In[1]:= |
| Out[1]= |
Test whether "the Morse code" is an anagram of "Here come dots":
| In[2]:= |
| Out[2]= |
Test whether "extraterrestrial" is an anagram of "xylophone":
| In[3]:= |
| Out[3]= |
AnagramQ accepts more than two arguments and will check if all of them are anagrams of one another:
| In[4]:= |
| Out[4]= |
| In[5]:= |
| Out[5]= |
Use the option IgnoreCase to ignore the case of the letters:
| In[6]:= |
| Out[6]= |
| In[7]:= |
| Out[7]= |
Use the option IgnoreDiacritics to ignore diacritics:
| In[8]:= |
| Out[8]= |
| In[9]:= |
| Out[9]= |
Use the option "IgnoreSpaces" to decide whether or not to ignore spaces:
| In[10]:= |
| Out[10]= |
| In[11]:= |
| Out[11]= |
Look for anagrams of a word using the built-in dictionary:
| In[12]:= |
| Out[12]= |
Test whether two sentences are anagrams of one another:
| In[13]:= |
| Out[13]= |
Two equal strings are not considered anagrams:
| In[14]:= |
| Out[14]= |
Two empty strings are also not considered anagrams of one another:
| In[15]:= |
| Out[15]= |
AnagramQ returns True if a single argument is supplied:
| In[16]:= |
| Out[16]= |
AnagramQ returns True if no arguments are supplied:
| In[17]:= |
| Out[17]= |
Depending on $Language the option IgnoreDiacritics can affect the outcome:
| In[18]:= | ![]() |
| Out[18]= |
| In[19]:= | ![]() |
| Out[19]= |
Find anagrams with six or more words with at least five letters:
| In[20]:= | ![]() |
| Out[26]= | ![]() |
Confirm that all the groups of words are anagrams:
| In[27]:= |
| Out[27]= |
This work is licensed under a Creative Commons Attribution 4.0 International License