2

My approach is as follows: Total no. of permutations - abc appears once - twice - thrice

$For \ 1 \ abc \ : \ $ We can arrange $ \ a,b,c,a,b,c \ $ (in $\frac{6!}{2!2!2!}$ ways),then subtract the cases where $abc$ appears atleast once, by taking $abc$ as a unit and then arranging $a,b,c,abc$ (it can be done in 4! ways). Atlast insert an $abc$. ei $$(\frac{6!}{2!2!2!} - 4!)\times {}^7C_1$$

$For \ 2 \ abc \ : \ $ Arrangement of $ \ abc,abc,a,b,c \ $ (in $\frac{5!}{2!}$ ways), subtracting the cases where $ \ abc \ $ occurs thrice (3 ways : $ \ a,b,c,abc,abc \ $ or $ \ abc,a,b,c,abc \ $ or $ \ abc,abc,a,b,c \ $) ei. $$\frac{5!}{2!} -3$$

$For \ 3 \ abc \ : \ $ Only 1 way

Hence, Total no. of permutations - abc appears once - twice - thrice $$ = (\frac{9!}{3!3!3!} - ((\frac{6!}{2!2!2!} - 4!)\times {}^7C_1+(\frac{5!}{2!} -3)+1)$$ $$= 1160$$

Whereas the answer should be 1109. Where am i over/under counting cases ? Is there a better solution?

Sh0unak
  • 75
  • 1
    It seems like the best way to do this is with Inclusion/Exclusion. Let $A$ be the set of all permutations of the lettters, and $A_i$ be the number of permutations where $abc$ starts at index $i,$ for $i=1,\dots,8.$ You want $A\setminus (A_1\cup\cdots\cup A_8).$ If course, $A_i\cap A_j$ is empty of $i\neq j$ and $|i-j|<3.$ And $A_i\cap A_j\cap A_k$ is empty if $i<j<k$ when $A_i\cap A_j$ is empty or $A_j\cap A_k$ is empty. – Thomas Andrews May 28 '24 at 15:55
  • 5
    Is your word correct? You have $9!$ in places, yet your word has $10$ characters. It looks like you might have added an extra "a" by accident. – lulu May 28 '24 at 16:08
  • +1 : For showing a very detailed attempt to conquer the problem. In judging the quality of your posted question, with respect to MathSE protocol, I regard it as irrelevant that your work has an analytical error, as indicated by the answer of Rupert Rybka. I am therefore surprised that anyone would vote to close this question. – user2661923 May 28 '24 at 20:17

3 Answers3

2

I think the problem is with counting the number of ways for the case For 1 $abc$.

The problem is the fact, that when you plug your $abc$ in the end it can possibly land inside some other $abc$ in your subsequence, eventually making a correct sequence. For example: $$ abccba \rightarrow a\color{red}{abc}bcbca $$ But you missed that possibility in your approach.


Now what I have done is splitting this into some cases based on the location of our $abc$ in the sequence. I will focus of rearangements of remaining letters that form at least one more $abc$. Total number of ways to do so without that restriction is as you mentioned $\frac{6!}{2! \cdot 2! \cdot 2!}$.

Case $1$: $abc\_ \,\_\,\_\,\_\,\_\,\_$

Now we have, as you mentioned we have $abc, a, b ,c$ and we can arrange them in $4!$ ways, but we get two the same which are $abc, a, b ,c$ and $a, b, c, abc$ so we have: $\boxed{4! - 1}$ bad ways.

Case $2$: $\_abc \,\_\,\_\,\_\,\_\,\_$

Now we have to put $abc$ in the right part of this expression on $3$ ways and arrange other letters in $3!$ ways (we can see that, they can't form another $abc$). In total we have $\boxed{3 \cdot 3!}$ bad ways.

Case $3$: $\_\,\_abc\_\,\_\,\_\,\_$

Similarly we have to put $abc$ in the right part of this expression on $2$ ways and arrange other letters in $3!$ ways. So in total we have $\boxed{2 \cdot 3!}$ bad ways.

Case $4$: $\_\,\_\,\_abc\_\,\_\,\_$

Now $abc$ will land either on left or the right side, and rearangement of remaining letters will give us $3!$ ways. But the is one way that we count twice which is $abcabcabc$ so in total we have $\boxed{2\cdot 3! - 1}$ bad ways.

There are $3$ remaining cases, which are symmetric to cases $1, 2$ and $3$ so we don't have to consider them separately.

Thus the number of sequences with just one $abc$ is: $$ 7\cdot \frac{6!}{2!\cdot 2!\cdot2!} - 2\cdot(4! - 1 + 3 \cdot 3! + 2 \cdot 3!) - (2\cdot 3! - 1) = 513 $$


Your calculations for other cases are correct and thus you get: $$ \frac{9!}{3!\cdot3!\cdot3!} - (513 + \frac{5!}{2!} - 3 + 1) = 1109 $$

1

Since the answer of Rupert Rybka directly answers the original poster's question, I am going to expand on the comment of Thomas Andrews and provide an Inclusion-Exclusion answer.


See this article for an introduction to Inclusion-Exclusion. Then, see this answer for an explanation of and justification for the Inclusion-Exclusion formula.

Following the syntax in the 2nd link above, let $~S~$ denote the collection of all 9 character strings that contain 3 A's, 3 B's, and 3 C's.

For $~k \in \{1,2,\cdots,7\},~$ let $~S_k~$ denote the subset of $~S~$ that specifically contains the sequence ABC, starting in position $~k.~$ For example an element in $~S_1~$ would look like

A B C - - - - - -

where the string might or might not contain the sequence A B C after position 3.

Then, the desired enumeration is

$$| ~S ~| - | ~S_1 \cup S_2 \cup \cdots \cup S_7 ~|. \tag1 $$

Let $~T_0~$ denote $~| ~S ~|.$

Let $~T_1~$ denote $\displaystyle \sum_{1 \leq i_1 \leq 7} | ~S_{i_1} ~|.$

That is, $~T_1~$ represents the sum of $~\displaystyle \binom{7}{1} ~$ terms.

For $~r \in \{2,3,\cdots,7\},~$
let $~T_r~$ denote $\displaystyle \sum_{1 \leq i_1 < i_2 < \cdots < i_r \leq 7} | ~S_{i_1} \cap S_{i_2} \cap \cdots \cap S_{i_r} ~|.$

That is, $~T_r~$ represents the sum of $~\displaystyle \binom{7}{r} ~$ terms.

Then, in accordance with Inclusion-Exclusion theory, the computation in (1) above is equivalent to :

$$\sum_{r=0}^7 (-1)^r T_r.$$

So, the entire problem has been reduced to computing each of $~T_0, T_1, \cdots, T_r.$

As it turns out, this will be much easier than it looks.


$~T_0,~$ which denotes $~|S|~$ equals

$$\binom{9}{3} \times \binom{6}{3} \times \binom{3}{3} = 1680.$$

By considerations of symmetry,

$$T_1 = 7 \times | ~S_1 ~| = 7 \times \binom{6}{2} \times \binom{4}{2} \times \binom{2}{2} = 630.$$

That is, in $~S_1,~$ with A B C starting in position 1, from position 4 on, there are 2 A's, 2 B's, and 2 C's to be distributed.

At this point, I am going to postpone the computation of $~T_2,~$ which represents the most challenging computation in the problem. Instead, I will now compute $~T_3, T_4, \cdots, T_7.~$

Then, in the next section, I will use a special method to compute $~T_2,~$ and in the final section, I will complete the problem.

There is only one way that you can have 3 of the sets $~S_1, S_2, \cdots, S_7~$ intersect. That is with the string that specifically looks like

A  B  C  A  B  C  A  B  C

which represents $~S_1 \cap S_4 \cap S_7.$

So,

$$T_3 = 1.$$

By similar analysis, it is impossible to have a 9 character string that represents the intersections of $~4~$ or more of the $~S_1, ~S_2, ~\cdots, ~S_7 ~$ subsets.

Therefore,

$$0 = T_4 = T_5 = T_6 = T_7.$$


$\underline{\text{Computation of} ~T_2}$

$~T_2~$ could be computed manually. I prefer to do it analytically, because the corresponding analysis will be generally useful.

As illustrative examples, consider the following tableaus

Tableau-1 : - - i-1 - - i-2 -
Tableau-2 : i-1 - - i-2 - - -

In Tableau-1 above, $~i_1~$ and $~i_2~$ are placed specifically in positions $~3~$ and $~6.~$ This specific tableau represents the $~S_3 \cap S_6~$ intersection.

In Tableau-1, the placement of $~i_1~$ and $~i_2~$ create $~3~$ islands: the island before $~i_1;~$ the island after $~i_1;~$ and the island after $~i_2.$ Let $~x_1, x_2, x_3,~$ denote the respective size of each of these islands, reading the islands from left to right.

Then, you have $~(x_1,x_2,x_3) = (2,2,1).~$

Now consider Tableau-2, which represents $~S_1 \cap S_4.$
The $~3~$ islands that it creates are $~(x_1,x_2,x_3) = (0,2,3).~$

Let $~N~$ denote the number of possible $~S_{i_1} \cap S_{i_2}~$ intersections, that are consistent with the constraints of the problem.

Then,

$$T_2 = N \times \binom{3}{1} \times \binom{2}{1} \times \binom{1}{1} = 6N.$$

Stars and Bars theory can be used to compute $~N.$ For Stars and Bars theory, see this article and this article.

Each intersection represented by one of the terms used in the computation of $~T_2~$ is uniquely identified by its corresponding ordered triple $~(x_1, x_2, x_3).~$

$~N~$ will equal the number of solutions to

  • $~x_1 + x_2 + x_3 = 7 - 2 = 5.~$
    That is, there are $~7~$ positions, with $~2~$ of the positions taken by $~i_1~$ and $~i_2.$

  • $~x_1, x_3 \in \Bbb{Z_{\geq 0}}.$

  • $~x_2 \in \Bbb{Z_{\geq 2}}.$

The idea is that since $~S_{i_1}~$ represents a $~3~$ character string, the position of $~i_2~$ must be greater than or equal to $~(i_1 + 3).~$ This implies that $~x_2~$ must be $~\geq 2.$

Further, having $~x_1 = 0 ~$ merely represents that $~i_1 = 1,~$ which is perfectly acceptable. Similarly, having $~x_3 = 0 ~$ merely represents that $~i_2 = 7,~$ which is also perfectly acceptable.

Basic Stars and Bars theory requires that each of the variables be an element in $~\Bbb{Z_{\geq 0}}.~$

This is easily achievable, via $~y_2 = x_2 - 2 \implies y_2 \in \Bbb{Z_{\geq 0}}.$

So, the enumeration of $~N~$ has been transformed into enumerating the number of solutions to

  • $x_1 + y_2 + x_3 = (7 - 2) - 2 = 3.$

  • $x_1,x_3 \in \Bbb{Z_{\geq 0}}.$

  • $y_2 \in \Bbb{Z_{\geq 0}}.$

By Stars and Bars theory:

$$N = \binom{3 + [3-1]}{3-1} = \binom{5}{2} = 10.$$

Therefore,

$$T_2 = 6N = 60.$$

Note
The (alternative) manual computation of $~N~$ would be to reason that for each $~i_1 \in \{1,2,3,4\},~$ there are $~(5 - i_1)~$ compatible positions for $~i_2.~$

Therefore, $~\displaystyle N = \sum_{i_1 = 1}^4 (5 - i_1) = 10.$


$\underline{\text{Completion of the Problem}}$

The desired enumeration is

$$\sum_{r=0}^{7} (-1)^r T_r$$

$$= ( ~T_0 + T_2 ~) - ( ~T_1 + T_3 ~)$$

$$= ( ~1680 + 60 ~) - ( ~630 + 1) = 1109.$$

user2661923
  • 42,303
  • 3
  • 21
  • 46
1

This answer is based upon the Goulden-Jackson Cluster Method. We consider the set of words of length $n\geq 0$ built from a ternary alphabet $\mathcal{V}=\{a,b,c\}$ and the set $$B=\{abc\}$$ of bad words, which are not allowed to be part of the words we are looking for. We derive a generating function $A(z)$ with the coefficient of $z^n$ being the number of wanted words of length $n$. According to the paper (p.7) the generating function $A(z)$ is \begin{align*} \color{blue}{A(z)=\frac{1}{1-dz-\text{weight}(\mathcal{C})}}\tag{1} \end{align*} with $d=|\mathcal{V}|=3$, the size of the alphabet and $\mathcal{C}$ is the weight-numerator of bad words with \begin{align*} \text{weight}(\mathcal{C})=\text{weight}(\mathcal{C}[abc])=-z^3\tag{2} \end{align*}

We get from (1) and (2) \begin{align*} A(z)=\frac{1}{1-3z+z^3}\tag{3} \end{align*}

Since we want to count the number of valid words of length $n=9$ which contain $3$ a's, $3$ b's and $3$ c's, we mark the generating function with the characters $a,b$ and $c$. We obtain according to (3) \begin{align*} \color{blue}{A(z;a,b,c)}&\color{blue}{=\frac{1}{1-(a+b+c)z+abcz^3}}\tag{4}\\ &=1+(a+b+c)z+(a+b+c)^2z^2+\cdots\\ &\qquad+\left(a^9+9a^8b+9a^8c+\cdots+{\color{blue}{1\,109a^3b^3c^3}}\right.\\ &\qquad\qquad\quad\left.+\cdots+(b+c)^9\right)z^9+\cdots \end{align*} where the last line was calculated with the help of Wolfram Alpha.

Result: The blue marked coefficient of $a^3b^3c^3z^{9}$ shows there are $\color{blue}{1\,109}$ words of length $9$ over the alphabet $\mathcal{V}$ built from $3$ a's, $3$ b's and $3$ c's which do not contain $abc$.


Add-on: With respect to a comment we show how to do the coefficient calculation manually. We use the coefficient of operator $[z^j]$ to denote the coefficient of $z^j$ of a series. We can so write for instance \begin{align*} [z^j](1+z)^n=\binom{n}{j} \end{align*} We calculate the wanted coefficient $[a^3b^3c^3z^9]A(z;a,b,c)$ in a two-step approach by first calculating $[z^9]A(z;a,b,c)$ and then we calculate $[a^3b^3c^3]\left([z^9]A(z;a,b,c)\right)$.

First step: We obtain \begin{align*} \color{blue}{[z^9]}&\color{blue}{A(z;a,b,c)}=[z^9]\sum_{j=0}^{\infty}z^j\left((a+b+c)-abcz^2\right)^j\tag{5.1}\\ &=\sum_{j=0}^9[z^{9-j]}\left((a+b+c)-abcz^2\right)^j\tag{5.2}\\ &=\sum_{j=0}^4[z^{8-2j]}\left((a+b+c)-abcz^2\right)^{2j+1}\tag{5.3}\\ &=\sum_{j=1}^4[z^{8-2j}]\sum_{q=0}^{2j+1}\binom{2j+1}{q}(-abc)^qz^{2q}(a+b+c)^{2j+1-q}\tag{5.4}\\ &\color{blue}{=-\binom{3}{3}(abc)^3+\binom{5}{2}(abc)^2(a+b+c)^3}\\ &\qquad\color{blue}{-\binom{7}{1}(abc)(a+b+c)^6+\binom{9}{0}(a+b+c)^9}\tag{5.5} \end{align*}

Comment:

  • In (5.1) we perform a geometric series expansion of (4).

  • In (5.2) we apply the rule $[z^{p-q}]A(z)=[z^p]z^qA(z)$ and set the upper limit of the series to $9$ since other terms do not contribute to $[z^{9-j}]$.

  • In (5.3) we note that we only need to consider even powers of $z$ due to $\left((a+b+c)-abc\color{blue}{z^2}\right)^j$. Therefore we take only odd $j$ which means $j\to 2j+1, 0\leq j\leq 4$.

  • In (5.4) we expand the binomial. We start the outer sum with $j=1$, since $j=0$ does not contribute.

  • In (5.5) we select the coefficient of $[z^{8-2j}]$.

Second step: We now extract the coefficient from $a^3b^3c^3$ in (5.5). We obtain \begin{align*} &\color{blue}{[a^3b^3c^3]\left([z^9]A(z;a,b,c)\right)}\\ &\quad=-\binom{3}{3}+\binom{5}{2}[abc](a+b+c)^3\\ &\quad\qquad-\binom{7}{1}[a^2b^2c^2](a+b+c)^6\\ &\quad\qquad+\binom{9}{0}[a^3b^3c^3](a+b+c)^9\tag{6.1}\\ &\qquad=-\binom{3}{3}+\binom{5}{2}\binom{3}{1,1,1}-\binom{7}{1}\binom{6}{2,2,2}\\ &\quad\qquad+\binom{9}{0}\binom{9}{3,3,3}\\ &\qquad=-1+10\cdot\frac{3!}{1!1!1!}-7\cdot\frac{6!}{2!2!2!}+1\cdot\frac{9!}{3!3!3!}\tag{6.2}\\ &\quad=-1+60-630+1680\\ &\quad\;\color{blue}{=1\,109} \end{align*} in accordance with the result from above.

Comment:

  • In (6.1) we already respect the factors $(abc)^q$ by applying the same rule as in (5.2).

  • In (6.2) we select the coefficient of $[a^qb^qc^q], 1\leq q\leq 3$ by using trinomial coefficients.

Markus Scheuer
  • 112,413
  • 1
    +1 to your answer. Please keep in mind that I am totally uneducated in generating functions. I like your approach, and think that it is good to indicate how generating functions can solve the problem. This may motivate the original poster to learn generating functions. I have one question that you may or may not regard as an overly difficult question to answer. ...see next comment – user2661923 May 29 '24 at 02:14
  • 1
    How hard would it be, to extend your approach to analytically compute the $~a^3b^3c^3~$ coefficient of $~1109 ~?~$ That is, I am wondering how difficult it would be to extend your work to derive a closed form expression for the $~a^3b^3c^3~$ coefficient. Then, one might naturally use Wolfram Alpha, or the person's own computer program (perhaps in Java, C, or Python), to evaluate this closed form expression. I am looking for something like $$\left[ ~a_1 \times \binom{n_1}{k_1} ~\right] + \left[ ~a_2 \times \binom{n_2}{k_2} ~\right] + \cdots .$$ – user2661923 May 29 '24 at 02:19
  • @user2661923: Not too hard. :-) I've added a manual derivation. – Markus Scheuer May 29 '24 at 06:39