Altogether there are 10000 codes.
let x represent digit 1 that is repeating. Let y represent digit 2 that is repeating.
So the number of permutations of xxyy is:
4! / (2!*2!) = 6 # This is 4C2 or 4 choose 2.
There are 10 possible digits x could take and 9 possible digits y could take.
So altogether 540 ways for two repeating digits.
# Divide by 2 because when x = 0, y = 1 => 0011(xxyy) is the same as when y =1 , x =0 => 0011 (yyxx)
So actual number of permutations is 270.
Similarly the number of permutations of xxxy is:
4.
There are 10 possible digits x could take and 9 possible digits y could take.
So the number of total outcomes is 4*10*9 = 360
360 + 270 = 630
So to answer your question it come froms the rule of product axioms.
https://en.wikipedia.org/wiki/Rule_of_product