# How many 5-digit zip codes can there be with exactly two digits the same?

1,756

I presume you're talking about a $5$-digit zip code (not ZIP+4). To choose a zip code satisfying your condition, choose an ordered $4$-tuple of distinct digits from $0$ to $9$ ($10 \times 9 \times 8 \times 7 = 5040$ ways to do this), then choose an unordered pair of positions out of the $5$ (${5 \choose 2} = 10$ ways, and assign the $4$-tuple in order to this pair and the other positions. The total number of such codes is thus $5040 \times 10 = 50400$.

Share:
1,756
Author by

Updated on June 27, 2022

• Cookie less than a minute

How many 5-digit United States zip codes can there be with exactly one pair of digits? This includes both zip codes that correspond to an actual city, town, incorporated community, ghost town, etc. in the United States and zip codes that are not used currently.

Exactly one pair of digits means only two digits in a zip code can be the same, but the digits do not necessarily have to be next to each other.

Example zip codes that count:

• 99501 (Anchorage, AK) has one pair of $9$'s
• 02108 (Boston, MA) has one pair of $0$'s
• 63155 (St. Louis, MO) has one pair of $5$'s

Example zip codes that do not count:

• 59103 (Billings, MT) does not have any two digits to be the same
• 78727 (Austin, TX) has three--not two--digits to be the same
• 93388 (Bakersfield, CA) has two pairs--not one pair--of digits

I appealed to the fundamental counting principle, as usual.

Number of zip codes whose...

• first two digits are the same (e.g. 99501): $10 \cdot 10 \cdot 9 \cdot 8 \cdot 7$
• first and fourth digits digits the same (e.g. 02108): $10 \cdot 9 \cdot 8 \cdot 10 \cdot 7$
• fourth and fifth digits are the same (e.g. 63155): $10 \cdot 9 \cdot 8 \cdot 7 \cdot 7$

...etc.

Was that correct or not? I thought since order matters in writing a zip code that I had to consider all those cases. If so, how can I consider all possible cases using a combinatorial argument, with permutations specifically?

(I have little background in combinatorics, but I am nonetheless curious. This is not a homework question; hence, my curiosity for asking this here.)

• JMoravitz over 5 years
For "Fourth and Fifth digits the same" for example, once you have chosen the fourth digit there is no longer any choice to be made for the fifth, it must match the fourth in order to ensure it matches. You pick the result of the fourth and fifth simultaneously, making it only $10\cdot 9\cdot 8\cdot 7\color{grey}{\cdot 1}$ for this case. Now... how many cases are there? Could you explain this more easily without cases by deciding where the matching numbers are beforehand?
Position cases: (1,2), (1,3), (1,4), (1,5), (2,3), (2,4), (2,5), (3,4), (3,5), (4,5). So there are 10 cases, I believe.
• JMoravitz over 5 years
and how many ways can you choose two of the positions out of five (order not mattering) to place the matching numbers... five choices and we want to choose two of them. Instead of wasting time and effort writing them all out by hand as you have (because it is time consuming and prone to making mistakes), is there a convenient calculation we can make?
There are $5 \choose 2$ ways. However, I thought order matters in writing a zip code. That's why I wrote them all out initially.
I see now: since two numbers have to be repeating, regardless of the position, then the number of zip codes with, say, first two digits are matching (e.g. 99801) is actually $10 \cdot 1 \cdot 9 \cdot 8 \cdot 7$. It does not matter where the $1$ is placed in computations like that one (for e.g. fourth and fifth repeating digits, second and fourth, etc.); obviously every quantity will always be $10 \cdot 9 \cdot 8 \cdot 7$, no matter the positions. And then there are ${5 \choose 2 }= 10$ such positions. Hence, $(10 \cdot 9 \cdot 8 \cdot 7) \cdot (10)=50400$, just like @RobertIsrael's answer.
If now three digits in a zip code must match, then there are $(10 \cdot 9 \cdot 8) \cdot {5 \choose 3} = 7200$ such zip codes.
It should be $5040 \times 10 = 50400$, not $3024 \times 10$