Counting problem: 5-character ASCII strings containing at least one @

AI Thread Summary
The problem involves counting 5-character ASCII strings that contain the "@" character at least once. The correct approach uses the inclusion-exclusion principle, calculating the total number of strings as 128^5 and subtracting those without "@" as 127^5, resulting in 128^5 - 127^5. An incorrect method suggested counting the placements of "@" and multiplying by the choices for the remaining characters, leading to an overcount of strings with multiple "@" characters. The key error in the incorrect solution lies in failing to account for the combinations of multiple "@" placements, which skews the total. Understanding the nuances of combinatorial counting is crucial in solving such problems accurately.
Nick O
Messages
158
Reaction score
8

Homework Statement



How many strings of five ASCII characters contain the character @ ("at" sign) at least once? [Note: there are 128 different ASCII characters.]

Homework Equations



The rule of product and inclusion-exclusion principle are relevant.

The Attempt at a Solution



The correct solution is as follows:

The number of 5-character ASCII strings is 128^5. The number of 5-character ASCII strings not including at least one @ is 127^5. By the inclusion-exclusion principle, the number of 5-character ASCII strings including at least one @ is equal to 128^5 - 127^5.

I have no problem with that. What bothers me is that I can't find out where I go wrong with the following "solution", which yields a different answer.

Incorrect solution:

At least one of the five characters is an @. There are 5 ways to place this character, because the string has a length of 5. The remaining characters may or may not be an @ symbol. Each of the four remaining characters can be chosen in 128 different ways.

By the rule of product, there are 5 * 128 * 128 * 128 * 128 = 5*128^4 such strings.

Query:

128^5 - 127^5 is a much larger number than 5*128^4. Which assumption in my incorrect solution is unjustified?
 
Physics news on Phys.org
Nick O said:

Homework Statement



How many strings of five ASCII characters contain the character @ ("at" sign) at least once? [Note: there are 128 different ASCII characters.]

Homework Equations



The rule of product and inclusion-exclusion principle are relevant.

The Attempt at a Solution



The correct solution is as follows:

The number of 5-character ASCII strings is 128^5. The number of 5-character ASCII strings not including at least one @ is 127^5. By the inclusion-exclusion principle, the number of 5-character ASCII strings including at least one @ is equal to 128^5 - 127^5.

I have no problem with that. What bothers me is that I can't find out where I go wrong with the following "solution", which yields a different answer.

Incorrect solution:

At least one of the five characters is an @. There are 5 ways to place this character, because the string has a length of 5. The remaining characters may or may not be an @ symbol. Each of the four remaining characters can be chosen in 128 different ways.

By the rule of product, there are 5 * 128 * 128 * 128 * 128 = 5*128^4 such strings.

Query:

128^5 - 127^5 is a much larger number than 5*128^4. Which assumption in my incorrect solution is unjustified?

No, 5*128^4 is larger than 128^5-127^5. It's because you are overcounting strings that contain more than one @.
 
  • Like
Likes 1 person
In the incorrect solution your over counting.

Example:
Suppose we fix the first element with @.
then our string is of the form @0000. where the 0 can be any other ASCII character. But note we have @@000 as being one such character. But if we fix the second character so we have the set of strings of the form 0@000. Clearly if we let the first character be @, then we again have a string of the form @@000.
 
Last edited:
  • Like
Likes 1 person
Sorry, I somehow got that inequality backwards when translating it to a forum post.

That makes perfect sense. The devil is in the detail, particularly where combinations are involved. Thank you both!
 
I tried to combine those 2 formulas but it didn't work. I tried using another case where there are 2 red balls and 2 blue balls only so when combining the formula I got ##\frac{(4-1)!}{2!2!}=\frac{3}{2}## which does not make sense. Is there any formula to calculate cyclic permutation of identical objects or I have to do it by listing all the possibilities? Thanks
Since ##px^9+q## is the factor, then ##x^9=\frac{-q}{p}## will be one of the roots. Let ##f(x)=27x^{18}+bx^9+70##, then: $$27\left(\frac{-q}{p}\right)^2+b\left(\frac{-q}{p}\right)+70=0$$ $$b=27 \frac{q}{p}+70 \frac{p}{q}$$ $$b=\frac{27q^2+70p^2}{pq}$$ From this expression, it looks like there is no greatest value of ##b## because increasing the value of ##p## and ##q## will also increase the value of ##b##. How to find the greatest value of ##b##? Thanks
Back
Top