top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

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

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

Share this puzzle
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

+2 votes
 
Best answer

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)
answer May 11, 2015 by Salil Agrawal
–1 vote

there are 400

answer May 12, 2015 by Ben Gichuhi



Similar Puzzles
0 votes

Can you find a seven digit number which describes itself.

The first digit is the number of zeros in the number.
The second digit is the number of ones in the number, etc.

For example, in the number 21200, there are 2 zeros, 1 one, 2 twos, 0 threes and 0 fours.

+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?

+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?

...