# What is the probability that each book does not have a neighbour of the same color?

There are $13$ identical books which differ only in color: $2$ red, $5$ black and $6$ blue. They were randomly placed in a row. What is the probability of the event that there are no books of same color standing $2$ in a row?

At first, I tried to put $6$ blue books in a row so there will be at least one space between them, and I found out that there are ${7 \choose 1}^2$ combinations to do so. But I do not know what to do next.

• i guess answer is $\dfrac{103}{18018}$ Dec 26 '16 at 13:43
• @lapalap can you please tell us the answer. Dec 26 '16 at 16:46
• @KanwaljitSingh i am sorry, but i don't know the correct answer Dec 26 '16 at 17:11

A useful sample space consists of $13!$ equally probable arrangements of the thirteen books.   Certainly the books may be indistinguishable except by colour, but they are still distinct objects.   This makes weighting the probability of the favoured event...well not exactly easy, but far less complicated.

So...

In order for the six blue books not to be together there must be at least one book in the five spaces between them, leaving two additional books.

We can arrange the six blue books in $6!$ ways, then the seven spaces between them, $\rm\Box B\Box B\Box B\Box B\Box B\Box B\Box$, must be filled with:

• All seven spaces with $1$ book.
• One of the two ends with $0$, one of the other six spaces with $2$ (of different colours), the remaining five with $1$.
• Both ends with $0$, one of the other five with $3$ (one of a colour sandwiched between two of the other), the remaining four with $1$ book.
• Both ends with $0$, two of the other five with $2$ different colours the remaining three with $1$ book.

So by counting ways to select and arrange these groups, adding and dividing by the size of the sample space we have a probability of:

$$\dfrac{6!\Bigl({7!+\tbinom 21\cdotp \tbinom 61\cdotp \tbinom 51\cdotp \tbinom 21\cdotp 2!\cdotp 3!+\tbinom 51\cdotp\bigl(\tbinom 52\cdotp\tbinom 21+\tbinom 51\cdotp\tbinom 22\bigr)\cdotp 2!\cdotp 4!+\tbinom 52\cdotp\tbinom 52\cdotp\tbinom 22\cdotp 2!^4\cdotp 3!}\Bigr)}{13!}$$

$$\dfrac{103}{18018}$$

• How you are getting 206? Dec 26 '16 at 16:09
• Thank you for your answer, but can you tell a bit more about how did you get this fraction? Dec 26 '16 at 16:25
• @lapalap All seven spaces with one book: There are $\binom{7}{2}$ ways to choose which two of the seven spaces will receive a red book. The remainder must be filled with black books. One of the ends with $0$, one of the other six spaces with $2$ (of different colours), the remaining five with $1$: Choose one of the two ends to receive a book. Choose which of the six spaces will receive two books. Choose one of the two possible orders for the colors in that space. Choose which of the other five spaces will receive a red book. $$\binom{2}{1}\binom{6}{1}\binom{2}{1}\binom{5}{1}$$ Dec 26 '16 at 19:24
• @lapalap Both ends with $0$, one of the other five with $3$ (one of a colour sandwiched between two of the other), the remaining four with one book: Choose which of the five spaces will receive three books. If a black book is sandwiched between two red books, the other spaces must be filled with black books. If a red book is sandwiched between two black books, choose which of the other four spaces will be filled with the remaining red book. $$\binom{5}{1} + \binom{5}{1}\binom{4}{1}$$ Dec 26 '16 at 19:31
• @KanwaljitSingh: I think now is a good time to revoke your down-vote (and perhaps even replace it with an up-vote)... Dec 26 '16 at 20:44

Total number of arrangements possible $=\dfrac{13!}{2!\times 5! \times 6!}=36036$

Number of arrangements where no two adjacent books with same colors $=206$

Required probability $=\dfrac{206}{36036}=\dfrac{103}{18018 }$

How I got number of arrangements where no two adjacent books with same colors $=206$

credit: permutation calculator with a smaller example 'AABBBBCCCCC' and generated question number 15

Using the following notations
R: Red book
B: Blue book
b: black book

Part (1): Find number of arrangements where blue books are apart and black books are apart.

Arrange $2$ red books. Arrange the $5$ black books in any of the three positions as [bbbb] [b] [b]. Take $2$ blue books and separate the adjacent bbb. Remaining $4$ books can be arranged in remaining $6$ positions. So,
$\dbinom{3}{1}\dbinom{6}{4}=45$

Arrange $2$ red books. Arrange the $5$ black books in any of the three positions as [bbbb] [b] . Take $3$ blue books and separate the adjacent bbbb. Remaining $3$ books can be arranged in remaining $5$ positions. So,
$\dbinom{3}{1}\dbinom{2}{1}\dbinom{5}{3}=60$

Arrange $2$ red books. Arrange the $5$ black books in any of the three positions as [bbbbb]. Take $4$ blue books and separate the adjacent bbbbb. Remaining $2$ books can be arranged in remaining $4$ positions. So,
$\dbinom{3}{1}\dbinom{4}{2}=18$

Arrange $2$ red books. Arrange the $5$ black books in any of the three positions as [bbb] [bb]. Take $3$ blue books and separate the adjacent bbb and bb. Remaining $3$ books can be arranged in remaining $5$ positions. So,
$\dbinom{3}{1}\dbinom{2}{1}\dbinom{5}{3}=60$

Arrange $2$ red books. Arrange the $5$ black books in any of the three positions as [bb] [bb] [b]. Take $2$ blue books and separate the adjacent bb and bb. Remaining $4$ books can be arranged in remaining $6$ positions. So,
$\dbinom{3}{2}\dbinom{6}{4}=45$

Total: $228$

Part (2): Find number of arrangements where blue books are apart and black books are apart but red books are together

Group the red books and consider as $1$ big red book.

Arrange $1$ big red book. Arrange the $5$ black books in any of the two positions as [bbbb] [b] . Take $3$ blue books and separate the adjacent bbbb. Remaining $3$ books can be arranged in remaining $4$ positions. So,
$\dbinom{2}{1}\dbinom{4}{3}=8$

Arrange $1$ big red book. Arrange the $5$ black books in any of the two positions as [bbb] [bb] . Take $3$ blue books and separate the adjacent bbbb. Remaining $3$ books can be arranged in remaining $4$ positions. So,
$\dbinom{2}{1}\dbinom{4}{3}=8$

Arrange $1$ big red book. Arrange the $5$ black books in any of the two positions as [bbbbb] . Take $4$ blue books and separate the adjacent bbbbb. Remaining $2$ books can be arranged in remaining $3$ positions. So,
$\dbinom{2}{1}\dbinom{3}{2}=6$

Total: $22$

From Part(1) and (2),

## $228-22=206$

Verification: See this Python script which I got from stackoverlow.com (provided by Mr.David Eisenstat) through which I verified and $206$ is the number of arrangements where no similar books are consecutive.

• You should explain how you got $206$. Dec 26 '16 at 13:48
• Could you expand on how you found the number of arrangements with no two adjacent books sharing a color? That seems to be the key point here, and the question is asking about what steps to take to come up with the answer. Dec 26 '16 at 13:48
• i am adding that details. Dec 26 '16 at 13:49
• @Kiran I have simulated as well and i've got the same answer! Thank you! Dec 26 '16 at 18:55
• @KanwaljitSingh: I think now is a good time to revoke your down-vote (and perhaps even replace it with an up-vote)... Dec 26 '16 at 20:44

Arrange the 6 blue books in a row, creating 5 inner gaps.

$\textbf{1)}$ If the blue books appear in all 5 inner gaps, then there are 12 gaps remaining for the red books;

$\;\;\;$so there are $\binom{12}{2}$ possibilities.

$\textbf{2)}$ If the blue books appear in exactly 4 of the inner gaps, there are $\binom{5}{4}$ ways to choose these gaps, and

$\;\;\;$a red book must go in the 5th gap.

$\;\;$A) If the remaining blue book goes in an outside gap, there are 2 choices for this gap and then 11 gaps in $\hspace{.27 in}$which to put the remaining red book.

$\;\;$B) If the remaining blue book goes in one of these 4 inner gaps, there are 4 choices for this gap and then $\hspace{.3 in}$the remaining red book must go between the 2 adjacent blue books.

$\textbf{3)}$ If the blue books appear in exactly 3 of the inner gaps, there are $\binom{5}{3}$ ways to choose these gaps; and then

$\;\;\;$the red books must fill the remaining inner gaps and the other blue books must go in the 2 outer gaps.

This gives a probability of $\displaystyle\frac{\binom{12}{2}+\binom{5}{4}\left(2\cdot11+4\right)+\binom{5}{3}}{\binom{13}{6}\binom{7}{2}}=\frac{206}{36036}=\frac{103}{18018}$.