Print the number 5

A computer prints all of the integers from 1 1 to 3456 3456 . How many times does it print the digit 5 5 ?


The answer is 993.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

3 solutions

Arpit Dhimanj
Jul 2, 2014

993 times .There are 20 fives in the tens and ones places of one hundred numbers(10 in the ones place and 10 in the tens place).In each of the 500's,1500's, and 2500's there are 100 more fives in the hundreds places. So from 1 to 3400 there are (3 4 x 20)+(3 x 100) = 980 fives. And from 3400 to 3456 there are 13 more fives,for a total of 980+13=993 fives.

Mark Mottian
Jul 2, 2014

I will post a Python solution, if anyone is interested in knowing how to implement this using a program.

count = 0     #This keeps track of the number of fives
number = []     #This will be used to get each digit of the number

for x in range(1, 3457):
    if '5' in str(x):     
        number = list(str(x))     #separate each digit in 'x'
        #add the number of 5's to total
        count = count + number.count('5')    

print (count)

The program returns 993 as the answer.

I will post a CS solution.

1
Count[Flatten[Map[IntegerDigits, Range[1, 3456]]], 5]

Note that I am far from being good with Mathematica, so if you know a better way to solve this problem using Mathematica, please correct me.

are u sure this is the correct answer??... i can count smaller ipso 2200

aroop kundu - 6 years, 11 months ago

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...