# All Unique Permutations [closed]

We have the word: RAPSEVNOBLURKANIWA

We want to find the number of unique permutations that could be made with RAP always staying together, so that there are:

for every odd pair of adjacent consonants, the first letter is alphabetically smaller than the second, while
for every even pair - the opposite (the first letter is alphabetically bigger than the second).

example: in the given word: (1-odd)-P is smaller than S, (2-even)-V is bigger than N, (3-odd)-B is smaller than L, (4-odd)-R is bigger than K

• Isn't this essentially the same question as this but more difficult? Why, when you didn't accept any answer and it was put on hold? You haven't given any helpful feedback to answers in the last one. – Weather Vane Apr 12 '19 at 9:27
• Last one was disliked as it was too hard so I made it a bit easier and more understandable – Kradec na kysmet Apr 12 '19 at 9:29
• Last one had to be a fixed pattern of vowel and consonant, this has more arrangements of vowel/consonant. The last one wasn't put on hold because it was too hard, but because "This question is off-topic as it appears to be a mathematics problem, as opposed to a mathematical puzzle." I am not going to spend time on this problem, when it might be put on hold before I get there. – Weather Vane Apr 12 '19 at 9:31
• I am saying that a solution cannot be posted once the question is put on hold. – Weather Vane Apr 12 '19 at 10:31
• @trolley813 I did not downvote, and despite my comments submitted an answer. – Weather Vane Apr 12 '19 at 14:30

My answer (after the no-computer tag was removed) is

$$4419100800$$ unique solutions.

Unlike OP's previous puzzle there are $$132$$ valid permutations of vowel/consonant.
Placing RAP over each single-vowel position (except at the ends) gave me $$842$$ templates.
Removing RAP from RAPSEVNOBLURKANIWA leaves 6 vowels and 9 consonants.

The number of ways to arrange the remaining 6 vowels, with 1 duplicate A, is
$$\frac{6!}{2!} = 360$$

For each template, I recursively permuted the 9 consonants to comply with the rules.
After removing any duplicates there were $$12275280$$ solutions.

$$12275280 \times 360 = 4419100800$$ solutions, one of which is RAPSEVNOBLURKANIWA.

1. Since the RAP must always stand together, we can consider it as a single "letter" (a consonant).
2. So, now we have 16 letters, 10 consonants and 6 vowels. Let's substitute each consonant by 0 and each vowel by 1, and find all valid zero-one patterns.
3. We need to find number of permutations of 10 zeroes and 6 ones without 2 ones or 3 zeroes standing together. Each permutation is uniquely determined by the numbers of zeroes between adjacent ones (number of zeroes before 1st one, then between 1st and 2nd, etc.). Since there are 6 ones, there are 7 numbers which can be either 1 or 2 (since 0 would result into 2 ones standing together, and 3 or more will result into 3 zeroes standing together), however the 1st and last (7th) number can be zero. These numbers will sum up to 10 (since there are 10 zeroes in total), so there are either exactly 4 ones and 3 twos, or 1 zero, 2 ones and 4 twos, or 2 zeroes and 5 twos in these 7 numbers (since 1+1+1+1+2+2+2=0+1+1+2+2+2+2=0+0+2+2+2+2+2=10). The number of permutations with no zeroes will be exactly 7C3=7*6*5/(1*2*3)=35, with 1 zero will be 2*6C2=2*6*5/(1*2)=30 (since the zero can be either first or last), and with two zeroes 1 (only one: 0222220). Total number of ways is 35+30+1=66.
4. The vowels can be in any order, so there are 6!=720 ways to arrange them.
5. Now assign a digit 0 to 9 to each of the consonants according to their alphabetical order (here we can treat RAP as just P, since there are no letters between P and R (Qs are not present in the set)), and find number of valid permutations of 0123456789 for the all 66 cases.
6. Actually, the 66 cases can be reduced to 3 ones (with 3, 4 and 5 consonant pairs) since we can build a one-to-one correspondence between permutations for the cases having the same number of consonant pairs, so the number of valid sequences will remain the same.
7. So, the following 3 case classes are: find a permutation abcdefghij of 0123456789, where (1) a<b, c>d and e<f (35 cases); (2) the same as (1) and also g>h (30 cases); (3) the same as (2) and also i<j (1 case).
8. (Here I may be wrong) It's intuitively clear that the part of valid sequences will be 1/8, 1/16 and 1/32 of the total number of permutations (which is 10!=3628800), or 453600, 226800, and 113400 for the case classes (1), (2), and (3) respectively (since in each pair of digits, the first is either less or greater than the second, and this seems to be equally probable, but I cannot prove it) .
9. So, the final answer is 720*(35*453600+30*226800+1*113400)=16411248000

Edit: Tried to complete the answer, but step 8 may be incorrect.

• That's the hardest one :D – Kradec na kysmet Apr 12 '19 at 11:19
• @Kradecnakysmet Tried to complete it by myself. – trolley813 Apr 12 '19 at 11:37
• There is R that's not part of RAP – Kradec na kysmet Apr 12 '19 at 11:40
• Yes, but we can treat it as being alphabetically after the RAP. – trolley813 Apr 12 '19 at 11:41
• if 2nd R is before RAP it doesn't count as valid – Kradec na kysmet Apr 12 '19 at 11:42