The letters in the word PERPLEXUS can be arranged in 90720 ways.
If these arrangements are placed in alphabetical order and numbered (EELPPRSUX = 1), which number will PERPLEXUS be assigned?
Matlab commands:
>> a=string(sortrows(uniqueperms('perplexus')));
>> find(a=="perplexus")
ans =
32670
A more complex way--VB program:
Private Sub Form_Load()
x$ = "EELPPRSUX": n = 1
Do While x$ <> "PERPLEXUS"
permute x$
n = n + 1
Loop
Text1.Text = x$ & " " & n
End Sub
It finds:
PERPLEXUS 32670
Analytic solution:
If there had been no repeated letters in the word, the method described in
my solution to Permutation List would have been directly applicable. Modifying it a little to take care of the repeated letters:
Alphabetic order EELPPRSUX
Those that start with E or L all come before PERPLEXUS:
With E: 8!/2 = 20160
With L: 8!/4 = 10080
Those that start with PE followed next by E, L or P also precede PERPLEXUS:
PEE: 6! = 720
PEL: 6! = 720
PEP: 6! = 720
Those that start PER, but then continue with E or L:
PERE: 5! = 120
PERL: 5! = 120
Those that start PERP, but then continue with E:
PERPE: 4! = 24
Now, those that start PERPLE, have endings
SUX, USX, UXS, USX or XSU all before XUS.
That's 5 more, and then we add 1 because we want PERPLEXUS's ordinal number.
20160 + 10080 + 3*720 + 2*120 + 24 + 5 + 1 = 32670
I'll admit: the first time through this analytic version, I forgot to consider the sequences that start PEP, and wound up 720 short, which I wouldn't have noticed had I done the analytic version without the computer version.
|
Posted by Charlie
on 2022-08-08 08:48:10 |