Anagrams - Maple Help

StringTools

 Anagrams
 search for anagrams

 Calling Sequence Anagrams( word, wordlist )

Parameters

 word - Maple string; word to anagram wordlist - sorted list of strings; list of words to search for anagrams

Description

 • An anagram of a word (string) is a permutation of word. The Anagrams(word, wordlist) command searches wordlist for anagrams of word. An expression sequence of the anagrams of word is returned. The order of the strings in the returned expression sequence is not defined. If no anagrams are found, then the NULL expression sequence is returned.
 • The list wordlist is required to be a (lexicographically) sorted list of strings. (The requirement that the list be sorted is not currently used or enforced, but may be in a future implementation.)
 • You can generate the set of all anagrams of a string by using StringTools[Permute], together with combinat[permute], as illustrated in the following example.
 • All of the StringTools package commands treat strings as (null-terminated) sequences of $8$-bit (ASCII) characters.  Thus, there is no support for multibyte character encodings, such as unicode encodings.

Examples

 > $\mathrm{with}\left(\mathrm{StringTools}\right):$
 > $\mathrm{Anagrams}\left("edit",\left["foo","diet","bar","tide","baz","edit","dite","foobar"\right]\right)$
 ${"tide"}{,}{"diet"}{,}{"edit"}{,}{"dite"}$ (1)
 > $\mathrm{Anagrams}\left("flower",\left["foo","diet","bar","tide","baz","edit","dite","foobar"\right]\right)$

To generate all anagrams of a string, use Permute and combinat[permute].

 > $\mathrm{AllAnagrams}≔s::\mathrm{string}↦\mathrm{op}\left(\mathrm{map2}\left(\mathrm{StringTools}:-\mathrm{Permute},s,\mathrm{combinat}:-\mathrm{permute}\left(\mathrm{length}\left(s\right)\right)\right)\right)$
 ${\mathrm{AllAnagrams}}{≔}{s}{::}{\mathrm{string}}{↦}{\mathrm{op}}{}\left({\mathrm{map2}}{}\left({\mathrm{StringTools}}{:-}{\mathrm{Permute}}{,}{s}{,}{\mathrm{combinat}}{:-}{\mathrm{permute}}{}\left({\mathrm{length}}{}\left({s}\right)\right)\right)\right)$ (2)
 > $L≔\left[\mathrm{AllAnagrams}\right]\left("edit"\right)$
 ${L}{≔}\left[{"edit"}{,}{"edti"}{,}{"eidt"}{,}{"eitd"}{,}{"etdi"}{,}{"etid"}{,}{"deit"}{,}{"deti"}{,}{"diet"}{,}{"dite"}{,}{"dtei"}{,}{"dtie"}{,}{"iedt"}{,}{"ietd"}{,}{"idet"}{,}{"idte"}{,}{"ited"}{,}{"itde"}{,}{"tedi"}{,}{"teid"}{,}{"tdei"}{,}{"tdie"}{,}{"tied"}{,}{"tide"}\right]$ (3)
 > $\mathrm{evalb}\left(\mathrm{nops}\left(L\right)=4!\right)$
 ${\mathrm{true}}$ (4)