One day an extremely bored student began writing down the positive integers in order: 1,2,3,... When she got to 20 she noticed that she had used the digit 1 twelve times (once each for 1,10,12,13,...,19 and twice for 11). She asked herself if there was some number n (greater than 1) such that in writing down the integers from 1 to n she would have used the digit 1 exactly n times.
Is there such an n?
If so, is there a largest such n?
What if the digit 1 is replaced by another digit?
What if we work in a number base other than base 10?
The first that's greater than 1 is 199981, the list of those below 10 million follows:
1 1
1 199981
1 199982
1 199983
1 199984
1 199985
1 199986
1 199987
1 199988
1 199989
1 199990
1 200000
1 200001
1 1599981
1 1599982
1 1599983
1 1599984
1 1599985
1 1599986
1 1599987
1 1599988
1 1599989
1 1599990
1 2600000
1 2600001
The lefthand 1 indicates that that is the digit used. Only 1 works within this range.
For n = 1 To 10000000
ns$ = LTrim(Str(n))
For i = 1 To Len(ns)
d = Val(Mid(ns, i, 1))
dig(d) = dig(d) + 1
Next
For i = 1 To 9
If dig(i) = n Then
Text1.Text = Text1.Text & i & " " & n & crlf
End If
Next
DoEvents
Next
These are the only ones found under 10 million. I don't see any barrier to keep the number of such things finite, but there may be such a limit.
Up to 10 million, no other digit would replace the 1.
Altogether there seem to be 20 2digit numbers, 300 3digit number, 4000 4digit numbers, 50000 5digit numbers, etc., so the numbers keep pace.

Posted by Charlie
on 20190830 13:02:05 