StringTools - Maple Programming Help

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : Programming : Names and Strings : StringTools Package : Transformations : StringTools/Permute

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.

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

Was this information helpful?



Please add your Comment (Optional)
E-mail Address (Optional)
What is ? This question helps us to combat spam