I tried to write this problem, and I've realized I've completely gone off the tracks.
If we randomly scramble the letters of HAPPYEASTER, in how many ways can exactly 2 sets of the duplicated letters appear next to each other in the string?
Example of desired outcome:
AAPYHSPEERT
Easy Math Editor
This discussion board is a place to discuss our Daily Challenges and the math and science related to those challenges. Explanations are more than just a solution — they should explain the steps and thinking strategies that you used to obtain the solution. Comments should further the discussion of math and science.
When posting on Brilliant:
*italics*
or_italics_
**bold**
or__bold__
paragraph 1
paragraph 2
[example link](https://brilliant.org)
> This is a quote
\(
...\)
or\[
...\]
to ensure proper formatting.2 \times 3
2^{34}
a_{i-1}
\frac{2}{3}
\sqrt{2}
\sum_{i=1}^3
\sin \theta
\boxed{123}
Comments
Well, here's my brute-force solution. :) Running the following code (which could take around a minute due to the 2!2!2!11!=4,989,600 initial permutations) yields a total number of ways of 423,360 which is 16514 of the original permutations (for as yet unknown reasons).
Log in to reply
Or, for those who prefer one liners... :)
Your code is correct!
Start by selecting 2 of 3 sets of duplicated letters to group.
That can be done in (23) ways.
Next, the number of ways of arranging the string HA2PPYE2STR is given by:
(29)⋅7!
We must take away the number of instances where the result above yields all three duplicated letter sets grouped by noticing the string HA2P2YE2STR can be arranged in 8! ways:
This results in:
(23)⋅((29)⋅7!−8!)=423,360
Thank you @David Vreken for showing me the tactic in another post, and thank you for confirming by computational methods @David Stiff !
Log in to reply
So clever! I could have saved myself some pain by grouping the duplicate sets like that. It was that last step that I couldn't figure out. Thanks!
Would it be possible for you to annotate so I can try to understand the code? I've never written in Python.
Log in to reply
Sure thing! I've updated the code above.
I suppose it’s (8+7+6+5+4+3+2+1)×3=108 ways :) (possible positions times ways to choose 2/3)
Log in to reply
Really? Seems too simple. :)
I almost got it, but got stuck at the end. I figured there are 3 different pairs of duplicate sets we can use, 72 (I think) ways to arrange them, but then I couldn't figure out how many ways there are to arrange the remaining letters so that the last duplicate set didn't appear together...
Perhaps I should just code it up and find out. :)
Ohh yes! Thanks for reminding me that I had to fill in the other letters as well :P For the rest 7 letters, there are 27! combinations! So the desired number is 216×27!.
But we have to subtract the possibility of 3 pairs aligned :)