Permute - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.
Our website is currently undergoing maintenance, which may result in occasional errors while browsing. We apologize for any inconvenience this may cause and are working swiftly to restore full functionality. Thank you for your patience.

Online Help

All Products    Maple    MapleSim


StringTools

  

Permute

  

apply a given permutation to a string

 

Calling Sequence

Parameters

Description

Examples

Calling Sequence

Permute( s, perm )

Parameters

s

-

Maple string

perm

-

list of integers; permutation of 1 .. length(s)

Description

• 

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..lengths, 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.

Examples

withStringTools:

Permuteabc,1,2,3

abc

(1)

Permuteabc,1,3,2

acb

(2)

Permuteabc,2,1,3

bac

(3)

Permuteabc,2,3,1

bca

(4)

Permuteabc,3,1,2

cab

(5)

Permuteabc,3,2,1

cba

(6)

Permuteabc,2,1,4,3

Error, (in StringTools:-Permute) [2, 1, 4, 3] is not a permutation of 1 .. 3

Permuteabc,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:

AllPermutationsuvw

uvw,uwv,vuw,vwu,wuv,wvu

(7)

AllPermutationsabcd

abcd,abdc,acbd,acdb,adbc,adcb,bacd,badc,bcad,bcda,bdac,bdca,cabd,cadb,cbad,cbda,cdab,cdba,dabc,dacb,dbac,dbca,dcab,dcba

(8)

See Also

string

StringTools

 


Download Help Document