StringTools
Permute
apply a given permutation to a string
Calling Sequence
Parameters
Description
Examples
Permute( s, perm )
s
-
Maple string
perm
list of integers; permutation of 1 .. length(s)
The Permute(s, perm) command applies a given permutation perm to the string s.
The permutation perm must be a permutation of the integer 1..length⁡s, given as a list.
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.
with⁡StringTools:
Permute⁡abc,1,2,3
abc
Permute⁡abc,1,3,2
acb
Permute⁡abc,2,1,3
bac
Permute⁡abc,2,3,1
bca
Permute⁡abc,3,1,2
cab
Permute⁡abc,3,2,1
cba
Permute⁡abc,2,1,4,3
Error, (in StringTools:-Permute) [2, 1, 4, 3] is not a permutation of 1 .. 3
Permute⁡abc,2,3,3
Error, (in StringTools:-Permute) [2, 3, 3] is not a permutation of 1 .. 3
Using combinat[permute] you can construct all permutations of a string.
AllPermutations := proc( s::string ) local p; seq( StringTools:-Permute( s, p ), p = combinat[ 'permute' ]( length( s ) ) ) end proc:
AllPermutations⁡uvw
uvw,uwv,vuw,vwu,wuv,wvu
AllPermutations⁡abcd
abcd,abdc,acbd,acdb,adbc,adcb,bacd,badc,bcad,bcda,bdac,bdca,cabd,cadb,cbad,cbda,cdab,cdba,dabc,dacb,dbac,dbca,dcab,dcba
See Also
string
Download Help Document