I think the last sentence of the second bullet has small error in description even the code is right:

"2) If di == 1, then the number of 1s on di == factor * (di+1 - 1 + 1) + (number below di + 1).

Eg. For n == 713, there are in total 7 1s on the ten's digit, when the digit on the hundreds could be (0~6). And for each 1s on the ten's digit, it could appear 4 times when the one's digit varies from (0~3) for each ten."

Original:

"And for each 1s on the ten's digit, it could appear 4 times when the one's digit varies from (0~3) for each ten."

Could be:

And when the hundred's digit is 7, and the ten's digit is 1, it has only 4 times for the one's digit which varies from (0~3).