TITLE: How many strings of five ASCII characters contain the character @ (“at” sign) at least once?
QUESTION [5 upvotes]: I'm given the question: "How many strings of five ASCII characters contain the
character @ (“at” sign) at least once?"
Note: There are 128 different ASCII characters.
I realized I'd have to use rule of product and sum on this one right away. I approached it by figuring out 5 cases and summing them to get the answer.
Case I:
@ is contained once in the string
I have to pick the position of @ which can be done in 5 ways. Then I have to pick the remaining 4 characters which can be done in $127^4$ ways.
$5 * 127^4$ ways to do this case
Case II:
I have to pick the position of the first @ (5 ways to do that) then the position of the second @ (4 ways to do that) then $127^3$ ways to pick the remaining characters from the string. $5*4*127^3$ ways to do this step
Case III:
I have to pick the position of the first second and third @. Then I have to pick the remaining $2$ characters. $5*4*3*127^2$ ways to do this step.
Case IV:
I have to pick the position of first,second,third, and fourth @. Then I have to pick the last character. $5*4*3*2*127$ ways to complete this step.
Case V:
The whole string is @. Only one way to do this step.
I summed all my cases and the result was $1,342,673,846$ the back of the book gave the answer $1,321,368,961$. Where did I go wrong?

REPLY [3 votes]: In your cases $II, III, IV$ you have overcounted because swapping the $@$ signs results in the same string.  So in case $II$, instead of $5 \cdot 4$ ways to choose where the $@$ signs are, there are $5 \choose 2$  The fact that you are close supports that there are $128$ total ASCII characters  
Less work is to compute how many total strings there are and subtract the ones with no $@$.  $128^5-127^5=1,321,368,961$

REPLY [2 votes]: The simplest way to do this problem is to compute the number of strings $128^5$, and the number of strings with no @ character, $127^5$. So the total is $128^5-127^5$.
But $5\cdot 4$ is not the number of ways to pick two positions for the @ character, since it counts selecting position $1$ then $2$ and picking position $2$ then $1$. So it should be $\frac{5\cdot 4}{2\cdot 1}=\binom{5}2$, and the result you'll get is really going to be the binomial formula applied to $(127+1)^{5}-127^5$, or:
$$\binom{5}{1}127^4 + \binom{5}{2}127^3+\binom{5}{3}127^2 + \binom{5}4127^1+\binom{5}{5}$$