For finding ‘n’ digit number

((n-4)*(10^(n-1)))+(2*(10^(n-2)))+(10^(n-3))+(10^3)

]]>0s: 2

1s: 0

2s: 2

3s: 0

I found the best way to “understand” the pattern is to change step f) in the original post and instead notice that the 2 must be the second or third digit.

A) When the 2 is the second digit, you just iterate through choice of the first digit, and the rest of each number is forced:

1210

22… impossible

3211000

42101000

521001000

etc

And you can informally see why the 6 case does not exist (you now need two 1s and they “clash”). There’s also a jump over the 5 case due to the extra 1.

B) If you consider the 2 as third digit, that means there are two 2s so the first digit must be 2, which means you only have to enumerate the choices of second digit:

2020

21200

This is why there’s the “extra” 4 case, and the fill-in for the 5.

Not sure if that helps, but it worked for me:-)

]]>