Pietro Z.
Pietro Z.

Reputation: 531

Unique permutation with strange circular repetitions

I have some string like this:

'RRSSTT'
'RRRSSSTTT'
'RRRRSSSSTTTT'
 etc...

I need to extract all unique permutation with this property:

With command perms I obtain all permutations (if string have 6 elements, permutations are 720). With uperms script I obtain all unique permutation (if string have 6 elements, permutations are 90). I've found uperm on mathworks (http://www.mathworks.com/matlabcentral/fileexchange/27321-unique-random-permutations).

Until here all works, but I need to write/find an other algorithm that generate permutations with above special property. If string is 'RRSSTT' the desired permutations have to be 15.

Someone already faced to this problem and could help me?

------EDIT------

There are 15 goups of equivalent string, some example are:

Group 1:          Group 6:        Group 11:

'RSTTSR'         'RSTSTR'         'RSSTRT'
'SRTTRS'         'SRTRTS'         'STSRRT'
'STRRTS'         'STRTRS'         'RSRTTS'
'RTSSTR'         'TRSRST'         'STTRSR'
'TRSSRT'         'TSRSRT'         'TRRSTS'
'TSRRST'         'RTSTSR'         'TRTSSR'

Group 2:          Group 7:        Group 12:

'RSTRST'         'RSSRTT'         'RSSTTR'
'SRTSRT'         'SSTRRT'         'SRRTTS'
'STRSTR'         'RRSTTS'         'STTRRS'
'RTSRTS'         'STTSRR'         'TRRSST'
'TRSTRS'         'TRRTSS'         'TSSRRT'
'TSRTSR'         'TTRSSR'         'RTTSSR'

Group 3:          Group 8:        Group 13:

'RSTSRT'         'SRRSTT'         'SRSTTR'
'STRSRT'         'SSRTTR'         'SRRTST'
'RSTRTS'         'RRTSST'         'RTRSST'
'STRTSR'         'TSSTRR'         'TSSRTR'
'TRSRTS'         'RTTRSS'         'TSTRRS'
'TRSTSR'         'TTSRRS'         'RTTSRS'

Group 4:          Group 9:        Group 14:

'SRTRST'         'RSRSTT'         'RRSSTT'
'SRTSTR'         'SSRTRT'         'SSRRTT'
'RTSRST'         'STSTRR'         'SSTTRR'
'TSRSTR'         'RRTSTS'         'RRTTSS'
'RTSTRS'         'TRTRSS'         'TTRRSS'
'TSRTRS'         'TTSRSR'         'TTSSRR'

Group 5:          Group 10:        Group 15:

'STRRST'         'SRSRTT'         'SRSTRT'
'RSTTRS'         'SSTRTR'         'RSRTST'
'SRTTSR'         'RRSTST'         'STSRTR'
'RTSSRT'         'TSTSRR'         'RTRSTS'
'TRSSTR'         'RTRTSS'         'TSTRSR'
'TSRRTS'         'TTRSRS'         'TRTSRS'

I need to return one string for each group, I prefer the string with R as firs letter. Sorry for notation change.

-----EDIT 1-----

I will try to explain why

str1='RSTRST' 

and

str2='STRSTR' 

are equivalent.

You have to consider 'R' in str1 and substitute it with 'S', substitute 'S' with 'T' and finally 'T' with 'R'. All strings in a group are right, but in each group all strings are equivalent and I need to take only one string from each group.

As beaker said, the rule of character replacement doesn't work always, I need to find the right role.

Upvotes: 2

Views: 206

Answers (1)

Daniel
Daniel

Reputation: 36710

I think now I understood your code, this would solve it:

  • Use uperm to generate a set with all possible solution.
  • Call [a]=unique(solution,'stable') for each solution returned by uperm and accept it only if RST is returned (or any fixed order).

Upvotes: 1

Related Questions