Strings and Palindromes Counting

combinatoricsdiscrete mathematicsmodular arithmetic

Hoping to check my work!

  1. How many length-5 strings have at least one each of the letters A,B,C. Meaning, it has to have at least one A, one B, and one C. I put down $3*3*3*2*1$. I thought so b/c you could have any for the first three, but if they were all the same, then you'd have to pick the other two, hence the $2 * 1$.
  2. How many length-5 number-based palindromes are there? I believe there's $10^3$ because you can do whatever for the first three digits, and once that's decided you only have one choice for the other 2 digits.

Best Answer

For question $1$, you should subtract from the total number of permutations, which is just $3^5$. If there are only two letters, say $A$ and $B$, there are $2^5$ ways to permute them. Now there are $3$ choose $2 = 3$ ways to choose the two letters, so there are $3 \cdot 2^5$ ways. But the $3$ combinations $AAAAA, BBBBB$ and $CCCCC$ are counted twice, as if you choose $A, C$, $AAAAA$ and $CCCCC$ are both valid arrangements. Hence you have to subtract $3 \cdot 2^5$ by $3$, so the total number of ways is $3^5 - \left(3 \cdot 2^5 - 3\right) = 150$.

For question $2$, you are correct except that the leftmost digit cannot be $0$. Therefore, there are only $9 \cdot 10 \cdot 10 = 900$ ways.

Related Question