12/08/2018, 14:30
Nth character in Concatenated Decimal String
If all decimal numbers are concatenated in a string then we will get a string which looks like string P as shown below. We need to tell Nth character of this string. P = “12345678910111213141516171819202122232425262728293031….” Examples: N= 10 10th character is 1 N = 11 ...
If all decimal numbers are concatenated in a string then we will get a string which looks like string P as shown below. We need to tell Nth character of this string.
P = “12345678910111213141516171819202122232425262728293031….”
Examples:
N= 10 10th character is 1
N = 11 11th character is 0
N = 50 50th character is 3
N = 190 190th character is 1
import math def find(n): i = 0 while n>0: i+=1 n-= math.floor(math.log10(i))+1 return str(i)[n-1] print(find(1000))
That's all ! Follow me on my blog: notes.minamidev.com