Ouputting all the permutations with repeated symbols in MATLAB

1 view (last 30 days)
Hi, so I have a problem that's very similar to the classic "Mississippi" permutations problem. That is, "How many different linear arrangements of the letters from the word, 'Mississippi' are there?" I know how to do the actual calculation to find this, you would just do the 11!/(2!*4!*4!*1!) = 34,650. My question is, is there a way where you could have MATLAB generate all of these 34,650 possible arrangements, not just calculate the number 34,650?

Accepted Answer

KSSV
KSSV on 14 Aug 2019
Edited: KSSV on 14 Aug 2019
Read about perms. After this, you can try unique and get the required output.
str = 'Mississippi' ;
S = perms(str) ;
iwant = unique(S,'rows') ; % output would be exactly 34650
  2 Comments
Mason Dyess
Mason Dyess on 14 Aug 2019
Thank you KSSV, this was very helpful. One more thing, if I wanted to apply this same concept to a lengthy number string, (Ex: [1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]) how would I do this? I tried perms, but the length of that vector exceeds the limit for the input you can do. I'm really just interested in seeing all the ways you could arrange the nonzero values in the vector.

Sign in to comment.

More Answers (0)

Categories

Find more on Discrete Math in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!