Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How would you do this sort of problem in general, for example, if the the letter sequence was longer and there were more conditions?

One way I used to solve this problem was to enumerate the possibilities (I counted 14):

   L => PLAY, PLYA
   A = > PALY, PLYA

   P => LPAY, LPYA
    A => LAYP, LAPY

    P => YPLA, YPAL
Y -- L => YLPA, YLAP
    A => YAPL, YALP

The other way I tried to think about this was to start with all possible combinations of the letters and subtract out letter combinations that didn't meet the given conditions.

4! - 3! if you start with A - 2 x 1 * 1 * 2 if you start with P or L but have Y as the second letter.

It would seem if you make the problem larger and add more conditions it becomes error prone to try to subtract out all the unacceptable combinations of letters.

share|cite|improve this question
up vote 3 down vote accepted

There are $4!=24$ possible permutations without any restrictions. How many are bad? There are $3!=6$ that have A as the first letter, and there are $3!=6$ that have Y as the second letter, so to a first approximation there are $24-6-6=12$ allowable permutations. But some of the bad permutations are bad because they have A as first letter and Y as second letter, and we subtracted these twice: once on account of the A, and once on account of the Y. To correct that first approximation, we need to add these ‘doubly bad’ permutations back into the total. There are $2!=2$ of them, so the final count is $24-6-6+2=14$.

This technique of counting is known as the method of inclusion-exclusion and can be extended to arbitrarily large problems, though the computations may become rather extensive.

share|cite|improve this answer

Without restrictions, there are $4!=24$ ways of rearranging the letters. $6$ have A in the first position (fix A and rearrange the others), and $6$ have Y in the second position. But now you've counted the rearrangements AY_ _ twice (once for each constraint, and they fit both), so add them back in (there are $2$) to cancel that out. So overall there are $24-6-6+2=14$ possible ways.

share|cite|improve this answer
+1. This is an application of the inclusion-exclusion principle. – Harald Hanche-Olsen Aug 23 '12 at 19:48

You can break this down into two cases.

Either the first letter is Y, or it is not Y. Thus, we have two disjoint cases.

First, let the first letter be Y. Then, for all options of letters in order, you have $$1\cdot 3\cdot 2\cdot 1 = 6.$$

Second, let the first letter not be Y. Then, we have $$2\cdot 2\cdot 2\cdot 1 = 8.$$

Adding these, because they are disjoint, leads to 14 possibilities.

share|cite|improve this answer
Oops! Had a typo in my first equation that I carried through. Fixed it now :) – Emily Aug 23 '12 at 19:49

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.