[Math] Combinatorics: calcaulating options of valid password of length 5 or 6 from letters and numbers

combinatorics

I did the following excercise using the Inclusion–exclusion principle, that's how we should do that excercise, but the answer does not match my regular calcaulation, why?

The user is required to choose a password which will uphold the following requirements:

Password length is 5 or 6 characters. Characters allowed are a-z, A-Z, 0-9.

The password must contain at least one lowercase letter, at least one uppercase letter and at least one digit.

How many different valid password can the user create?

First, I calcaulated total options of 5 letters and 6 letters pasword from (A-Z (26), a-z (26), 0-9 (10)).

which is $\ 62^5 + 62^6$

I made the following sets:

$\ A_1 = $ number of passwords which contains 0 lowercase letters (only uppercase and numbers).

$\ A_2 = $ number of passwords which contains 0 uppercase letters (only lowercase and numbers).

$\ A_3 = $ number of passwords which contains 0 numbers (only lowercase and uppercase).

$\ |A_1| = |A_2| = 36^5+36^6$

$\ |A_3| = 52^5+52^6$

$\ S_1 = |A_1|+|A_2|+|A_3| = 36^5+36^6+36^5+36^6+52^5+52^6=24,625,310,720$

next, I calcaulated the intersection of the sets.

$\ |A_1 \cap A_2|=10^5+10^6$

$\ |A_1 \cap A_3|= |A_2 \cap A_3|=26^5+26^6$

$\ S_2=10^5+10^6+26^5+26^6+26^5+26^6=642,694,304$

$\ S_3 = $ passwords which contains no lowercase, uppercase or numbers at all = 0

now I just calcaulated the total number of options $\ – (S_1+S_2-S_3)$

which is: $\ 57,716,368,416-25,268,005,024=32,448,363,392$

but it doesn't match this:

$\ (26*26*10*62*62) + (26*26*10*62*62*62) = 1,637,082,720$

my questions are why and which is the correct answer to this question?

Best Answer

Password length is 5 or 6 characters. Characters allowed are $a-z$, $A-Z$, $0-9$.

The password must contain at least one lowercase letter, at least one uppercase letter and at least one digit.

Use the inclusion, exclusion principal. $|\{lud\}| - |\{lu\}|-|\{ld\}|-|\{ud\}| + |\{l\}|+|\{u\}|+|\{d\}|$

$$C= (26\!+\!26\!+\!10)^5(26\!+\!26\!+\!10\!+\!1)\!-\!(26\!+\!26)^5(26\!+\!26\!+\!1)\!- 2(26\!+\!10)^5(26\!+\!10\!+\!1)\!+\!2(26)^5(26\!+\!1)\!+\!(10)^5(10\!+\!1)$$

$$C= (62)^5(63) - (52)^5(53) - 2(36)^5(37) + 2(26)^5(27)+(10)^5(11)$$

$$C= 57,\!716,\!368,\!416 - 20,\!150,\!813,\!696 - 4,\!474,\!497,\!024 + 641,\!594,\!304+1,\!100,\!000$$

$$C= 57,\!716,\!368,\!416 -24,\!625,\!310,\!720 + 642,\!694,\!304$$

$$C= 33,\!733,\!752,\!000$$


but it doesn't match this:

$(26∗26∗10∗62∗62)+(26∗26∗10∗62∗62∗62)=1,637,082,720$

That only counts passwords starting with one upper case, one lower case, and one digit, --in that order-- followed by 2 or 3 more symbols from any group.

It does not count, for instance, "$\mathrm{HeLL0}$"