## Brain teaser: digits

I heard an interesting, even though easy, problem in the brain teaser category.

The digits of the numbers between 1 and 1999 are concatenated together in this order to create a new number. What is the 1999 digit of this number?

After you solve it, remember that this is for a 5th grade kid :D.

Advertisements

Categories: Software
algorithms

! Spoiler alert !

Sure, a 5th grade kid would solve it right away if he knew Python 🙂

In : ”.join([str(i) for i in range(1,2000)])[1999 – 1] #0-indexed

Out: ‘7’

Anyway, manual method, could probably be solved easier:

First 9 numbers have 1 digit. – 1990 digits left

10-99 – 90 numbers have 2 digits – 1810 digits left

100-999 – 900 numbers have 3 digits but we only need 1810 digits -> 1810/3 = 603.33 -> the answer is the fist digit of the 603rd number in this category -> 703 -> 7