A pin can be composed of 4 or 5 characters short and each character can be a capital letter, lower case letter or a number

346 Views Asked by At

A pin can be composed of 4 or 5 characters short and each character can be a capital letter, lower case letter or a number. If each pin must be composed of one capital, a lower case letter and a number, how many possible pins are valid ?

My thinking is that:

First count the 4-character pin, which is 26*26*10*62, 26 for Cap and lower case, then 10 for (0-9), 62 for all Cap, lower case and 10 digit.

Then count the 5- character pin, which is 26*26*10*62*62

Which gives me 26,404,560 as total. However I was told is not correct. Any hints are appreciated.

1

There are 1 best solutions below

2
On

This is more complicated than you might think. Here is how you do it for the 4-character case:

Count the number of total PINs, valid or not: $62^4$.

Subtract:

  • the number of PINs without an upper-case letter ($36^4$)
  • the number of PINs without a lower-case letter ($36^4$)
  • the number of PINs without a digit ($52^4$)

But now you have subtracted some PINs twice, namely those PINs missing two compulsory categories. So you have to add these back on:

  • the number of PINs without any letter at all ($10^4$)
  • the number of PINs without any upper-case letter or digit ($26^4$)
  • the number of PINs without any lower-case letter or digit ($26^4$)

So the number of valid 4-character PINs is $62^4-36^4-36^4-52^4+10^4+26^4+26^4$. The 5-character case is similar.

Actually, looking back, it wasn't all that complicated!

This procedure (subtracting then adding, then (if necessary) subtracting and adding...) is called the Inclusion-exclusion principle, and is often useful in combinatorics.