StringTools - Maple Programming Help

Home : Support : Online Help : Programming : Names and Strings : StringTools Package : Combinatorics on Words : StringTools/IsPermutation

StringTools

 IsPermutation
 test whether a string is a permutation

 Calling Sequence IsPermutation( s )

Parameters

 s - string

Description

 • The IsPermutation(s) command returns the value true if the string s is a permutation of its support, and returns the value false otherwise. A string is a permutation if, and only if, each character in the string occurs exactly once.
 • Note that, since there are only $255$ distinct characters (byte values), the Pigeon-Hole Principle implies that no string permutation can exceed $255$ characters in length.
 • If s is the empty string, the command returns true.

Examples

 > $\mathrm{with}\left(\mathrm{StringTools}\right):$
 > $\mathrm{IsPermutation}\left(""\right)$
 ${\mathrm{true}}$ (1)
 > $\mathrm{IsPermutation}\left("abc"\right)$
 ${\mathrm{true}}$ (2)
 > $\mathrm{IsPermutation}\left("abcba"\right)$
 ${\mathrm{false}}$ (3)
 > $r≔\mathrm{rand}\left(1..10\right):$
 > $S≔\left\{\mathrm{seq}\right\}\left(\mathrm{Random}\left(r\left(\right),'\mathrm{lower}'\right),i=1..1000\right):$
 > $\mathrm{select}\left(\mathrm{IsPermutation}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{and}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathrm{IsPalindrome},S\right)$
 $\left\{{"a"}{,}{"b"}{,}{"c"}{,}{"d"}{,}{"e"}{,}{"f"}{,}{"g"}{,}{"h"}{,}{"i"}{,}{"j"}{,}{"k"}{,}{"l"}{,}{"m"}{,}{"n"}{,}{"o"}{,}{"p"}{,}{"q"}{,}{"r"}{,}{"s"}{,}{"t"}{,}{"u"}{,}{"v"}{,}{"w"}{,}{"x"}{,}{"y"}{,}{"z"}\right\}$ (4)