Number of 13-letter strings containing neither of two 6- and 7-letter substrings

51 Views Asked by At

I'd like to check my answer for the following exercise:

Find the number of $13$-letter strings that contain the neither of the substrings CHARITY nor HORSES.

An earlier exercise involved finding the number of strings containing CHARITY, for which I got $26^6\cdot7$ (Edit: Per discussion in comments) by treating CHARITY as one letter and multiplying $26^6$ by $\frac{7!}{(7-6)!}=7$ to account for all positions of the "letter" CHARITY in a string of length $7$. Subtract $2$ from this to omit the words starting and ending with HORSES.

By the same token, the number of words containing HORSES would be $26^7\cdot8$, and subtract $2$ to omit words starting and ending with CHARITY. Edit: Also per discussion in comments, I neglected exclusion of strings containing multiple copies of HORSES, of which there are $26\cdot3$.

There are only $2$ words containing both CHARITY and HORSES.

Then the number of words containing neither of these substrings is

$$26^{13}-((26^6\cdot7-2)+(26^7\cdot8-26\cdot3-2)-2)=\boxed{26^{13}-26^6\cdot7-26^7\cdot8+26\cdot3+6}$$

Is this correct?

1

There are 1 best solutions below

0
On BEST ANSWER

The number of $13$-letter words containing CHARITY is $26^6\cdot 7.$ You can start with any $6$-letter word and insert CHARITY in any of seven places. Not sure how you get $26^7\cdot 7!.$

Similarly, the number of ways to have HORSES in a $13$-letter word is approximately $26^7\cdot 8$, not $26^7\cdot 8!.$ But $26^7\cdot 8$ counts twice the cases where a word contains HORSES twice, so the actual number of such words is $26^7\cdot 8-26\cdot 3.$

As you noted, there are two words with both HORSES and CHARITY.

So the count is:

$$26^{13}-\left(26^6\cdot 7-2\right)-\left(26^7\cdot 8-26\cdot 3-2\right)-2$$

Which is equal to:

$$26^{13}-7\cdot 26^6-8\cdot 26^7+26\cdot 3 +2$$


An inclusion-exclusion argument would have $A$ be all the $13$-letter words, and $A_i$ all the words that contain the word CHARITY starting at position $i=1,2,\dots,7,$ and $B_j$ being all the words that contain the word HORSES at $j=1,2,\cdots,8.$ Note that $|A_i|=26^6$ and $|B_j|=26^7$ for all $i,j.$

If, if $i_1\neq i_2$ then $A_{i_1}\cap A_{i_2}=\emptyset.$ And there are $2$ $i,j$ such that $|A_{i}\cap B_j|=1,$ and otherwise the intersection is zero. There are three pairs $j_1\neq j_2$ such that $|B_{j_1}\cap B_{j_2}|=26,$ and otherwise the intersection is zero.

All the intersections of any three distinct sets from the $A_i,B_j$ are empty.

So, by inclusion-exclusion: $$\begin{align}|A\setminus\left(A_1\cup \cdots\cup A_7\cup B_1\cup\cdots B_8\right)|=|A|&-\sum_{i=1}^7|A_i|-\sum_{j=1}^{8}|B_i|\\&+\sum_{1\leq j_1<j_2\leq 8}|B_{j_1}\cap B_{j_2}| + \sum_{i=1}^{7}\sum_{j=1}^{8}|A_i\cap B_j|\\ =26^{13}&-7\cdot 26^6 - 8\cdot26^7\\&+3\cdot 26+2\end{align}$$

Basically, inclusion-exclusion helps us find the double-counting for us.

More generally, for a word with $N$ letters, you'd have:

$$\sum_{6i+7j\leq N}(-1)^{i+j}\binom{N-5i-6j}{i,j,N-6i-7j}26^{N-6i-7j}$$

words without any instance of CHARITY or HORSES, where $\binom{m}{i,j,k}=\frac{m!}{i!j!k!}$ when $i+j+k=m.$

In the case when $N=13,$ you only have to deal with the pairs $(i,j)=(0,0),(1,0),(2,0),(1,1).$

Things get more complicated if the words can overlap - say, when we replace HORSES with SHORES, then SHORES can occur twice separately or overlapping SHORESHORES. Or if we replace HORSES with STARCH, then we can get STARCHARITY.