# Running Out of Digits, Level 3

The challenge idea is credited to HelloWorld1337.

You initially have x of each digit from 0 to 9. This means you have x * 10 digits in total. This count for each digit is shown in the table below.

Digit 0 1 2 3 4 5 6 7 8 9
# Remaining x x x x x x x x x x

Now start counting by ones, from 1. Each time you say a number you must remove the digits required to make the number from your stockpile of digits. For example, after you have counted from 1 to 13, the above table now looks like:

As an example, if you counted from 1 to 13 and didn't skip any numbers, the above table will look like:

Digit 0 1 2 3 4 5 6 7 8 9
# Remaining x-1 x-6 x-2 x-2 x-1 x-1 x-1 x-1 x-1 x-1

What is the largest number x you can count to without running out of the digits needed to form the number?

• Welcome to Puzzling! It seems you have two definitions of x as a variable - lowercase "x" for the number of digits left, and uppercase "X" for the largest number created. I'd suggested changing one of those to a different letter to avoid confusion. Feb 5 at 19:46
• Makes sense! Thank you. My intent is for those to be the same number; I've edited them accordingly. Feb 5 at 20:01

199,981. Mmm. Not this. You can add more and still work: 199,990

Details:

Short answer: I wrote a script. I know, I know.
Roughly, though, 1 in 10 of each digit is a 1. Consider 199,990. Take the last 5 digits of 199,990 and it gives you ~99,995 ones. To this add the 99,990 ones for the hundred-thousands place and you get ~199,985.
At this value, each additional number is adding 1 additional 1 (in the hundred-thousands place), so you can increase/decrease until you get a second 1 somewhere else. So this suggests that for $$x\in [199,981;199,990]$$ you use exactly $$x$$ 1s to write out the numbers from 1 to $$x$$.
When you go to 199,980 you will have 1 one left over. When you get to 199,991, you will be 1 one short.

Edit: Paul Panzer is correct. He should get the tick. Here's a justification:

If $$x = k\times10^n-1$$ then the number of ones needed is $$kn10^{n-1}$$ plus an additional $$10^n$$ if $$k\geq2$$.
This can be used to show that $$1\times10^9.
With a bit of care, you can now add $$2\times10^8$$ and discover that $$x$$ is less than that. But you can add $$1\times10^8$$, so $$x>1.1\times10^9$$.
Continue with that process and you get 1,111,111,110 as the maximum $$x$$

• Scripts are good! Long time lurker--always appreciate what the programming gang here comes up with to solve these kids of questions. I kind of figured someone would either have a script or some simple-but-elegant proof of why it is what it is. Feb 8 at 14:20
• I think if Paul Panzer's answer is correct, then it's clearly a larger number than mine. I haven't checked it, but it looks good. Feb 8 at 17:51