The U.S. uses 5-digit zip codes to help determine where mail goes. Since mail can be oriented in all sorts of directions, they avoid assigning zip codes that could be confused with a different zip code when read upside-down. For example, 61666 could be confused with 99919 when upside-down, so mail could be accidentally routed to the wrong zip code if both were actual zip codes.

How many zip codes could be confused with a different zip code when read upside-down?

In the example above, 61666 and 99919 would count as two confusing zip codes. Also, zip codes are allowed to start with 0, such as 00501.

#### Solution

There are 3050 confusing zip codes.

There are only 5 digits that read as valid digits when upside-down: 0, 1, 6, 8, and 9. This means there are 5^5 = 3125 possible 5-digit combinations that can be read upside-down.

However, some of these combinations read as the *same *zip code when upside-down, which is not a problem since we are looking only for zip codes that will be confused with a *different* zip code.

Zip codes that read the same when upside-down must have 0, 1, or 8 in the middle, the first digit is the last digit upside-down (i.e., a first digit of 0, 1, 6, 8, or 9 means the 1st digit must be 0, 1, 9, 8, or 6, respectively), and the 2nd digit is the 2nd last digit upside-down. This means there are 5 possibilities for the 1st digit, 5 possibilities for the 2nd digit, 3 possibilities for the middle digit, and only 1 possibility for the last two digits (since they have to match the first two digits): 5 x 5 x 3 x 1 x 1 = 75.

3125 combinations that can be read upside-down minus 75 combinations that read the *same *upside-down leaves us with 3050 combinations that read as a *different *zip code upside down.

Can 5s and 2s be confused when upside down (that answer depends on your font)