Holes in Numbers

Level pending

Have you ever noticed that 0 0 , 6 6 , 8 8 and 9 9 have holes in them?

An interesting problem is to count such holes in a given number.

For example, the number 68724 68724 and 59013 59013 have 3 3 and 2 2 holes respectively.

Counting the holes in relatively small numbers are pretty easy, but how about finding the holes in a 500 digits number?

How many holes are there in the 500-digits number?

You can find the number here .


The answer is 304.

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.

2 solutions

Lokesh Sharma
Feb 4, 2014

Finding holes in a 500 digits number is also pretty easy #_#

Python Solution:

s = '73475170547837298717289758738741902738962561728347902759816985230714827956107148923074836125897109823749812689356198072384798216398719856289178293749628510738497382965819072384718926589107389478912635812703894712935689127985723980719872398727340926358961098738472983065817083748972389751628356207348972037581969587832974089275868932724780217259837982783061985693274892507937857091738658327894702891789568397490723817085689730782789175873895793879480718739075893784278461856536821849023583798638291075'
tot = 0
for i in s:
    if i == '8':
        tot += 2
    elif i == '6' or i == '0' or i == '9':
        tot += 1

print tot        

>>> 304
Alds Ramos
Jan 24, 2014

Solution Using Java

public class holes {
        public static void main(String[] args)
    {
        String numb =   "73475170547837298717289758738741902738962561728347902759816985230714827956107148923074836125897109823749812689356198072384798216398719856289178293749628510738497382965819072384718926589107389478912635812703894712935689127985723980719872398727340926358961098738472983065817083748972389751628356207348972037581969587832974089275868932724780217259837982783061985693274892507937857091738658327894702891789568397490723817085689730782789175873895793879480718739075893784278461856536821849023583798638291075";
        int hole = 0;
        for(int i=0; i<numb.length(); i++)
        {
            switch(numb.charAt(i))
            {
                case '0': hole++; break;
                case '6': hole++; break;
                case '8': hole+=2; break;
                case '9': hole++; break;
            }
        }
        System.out.println(hole);
    }
}

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...