# sequence of numbers 1 to 3999 written like ( 123456789101112......3999) . Find the number of zeros in this sequence ?

+1 vote
116 views
sequence of numbers 1 to 3999 written like ( 123456789101112......3999) . Find the number of zeros in this sequence ?
posted May 11, 2015

Let me put in this way, its a permutation combination question with following parts
number of zeros from
1-9
10-99
101-999
1000-3999

For the first case the answer is 0
For the second case answer is [1-9]0 so 9
For the third case [1-9]0[0-9] + [1-9][0-9]0 = 9*1*10+9*10*1 = 180
For the third case [1-3]0[0-9][0-9]+[1-3][0-9]0[0-9]+[1-3][0-9][0-9]0 = 300+300+300 = 900

Total: 900+180+9 = 1089

Python Code

``````def countZeros(n):
result = 0
i = 1

while True:
b, c = divmod(n, i)
a, b = divmod(b, 10)

if a == 0:
return result

if b == 0:
result += (a - 1) * i + c + 1
else:
result += a * i

i *= 10

print countZeros(3999)
``````
–1 vote

there are 400

Similar Puzzles
+1 vote

3 rational numbers form a geometric progression in its current order.

1. If 8 is added to the middle number, then this new sequence forms an arithmetic progression.
2. If 64 is later added to the last number, then this yet another sequence forms a geometric progression again.
3. First number of these sequences is an integer.

Find the numbers?

+1 vote

23 x 64 gives the same answer as 46 x 32 (everything written in reverse order) can you find other pairs of two digit numbers with different digits that work like this?