Find the $n^{\rm th}$ digit in the sequence $123456789101112\dots$ [duplicate]

Consider a function $g(n)$, which is defined as: $$g(n)=\sum_{1\leqslant k \leqslant n} 9 \times 10^{k-1} \times k = \frac{ 9(n+1)10^n-10^{n+1}+1} {9} \qquad k,n \in \mathbb{Z^+}$$ You will probably see that the values can be calculated quite easily since there is a pattern: $$g(1)=9$$ $$g(2)=189$$ $$g(3)=2889$$ $$g(4)=38889$$ Now, given we want to find the $n$th digit we have to first solve $p$: $$ p=10^{\lceil a \rceil} -1 - \left\lfloor \frac{g( \lceil a \rceil) - g(a)}{\lceil a \rceil} \right\rfloor, g(a) = n \qquad a \in \mathbb{R^+}$$

This, $p$, will give us the number that contains the $n$th digit. So, in order to find the $n$th digit, calculate:

$$r = g(\lceil a \rceil ) - g(a) \mod \lceil a \rceil $$ The $r$ gives you the index of the $n$th digit in the number $p$.

$$p = (a_r\dots a_1a_0)$$

Reference: Los., Artem. (2014). Finding the nth digit in a sequence of positive integers placed in a row in ascending order.. Available: https://myows.com/protects/copyright/67407_mathexploration-pdf. Last accessed 3rd Jan 2014.