top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

    Get Free Puzzle Updates

Facebook Login
Site Registration

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

+1 vote
99 views
posted May 11, 2015 by Ankit Kamboj

Share this puzzle
Facebook Share Button Twitter Share Button Google+ Share Button LinkedIn Share Button Multiple Social Share Button

2 Solutions

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

there are 400

solution May 12, 2015 by Ben Gichuhi



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?

+4 votes

What number comes next in this sequence: 1 4 8 13 21 30 36 ??

Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...