2015 Countdown Problem #10: A Very Very Long Number

A person writes the numbers 1 to 2015 together as 123456789101112131415 201320142015 123456789101112131415…201320142015 Calculate the total number of occurrences where ‘15’ appears in the whole number.


The answer is 152.

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.

5 solutions

Discussions for this problem are now closed

Brock Brown
Dec 24, 2014

Done with four lines of Python:

1
2
3
4
s = ""
for i in xrange(1,2016):
    s = s + str(i)
print s.count('15')

Nikola Djuric
Dec 6, 2014

Numbers ending with 15 : 015,115,215,...,2015 (21 of them) but 1515 counted just once for now Numbers begining with 15:150-159,1500-1599, (110 of them) now 1515 counted second time Numbers between:1150-1159(10 of them) two numbers together 501|502,511|512...591|592 and 51|52(11 of them) So,there is 21+110+10+11=152 appears of '15'

Nice solution! :)

Wee Xian Bin - 6 years, 6 months ago

it is true

Ramanuj Jhawar - 6 years, 6 months ago
Wee Xian Bin
Dec 12, 2014

Here's the list of all the occurrences (not the solution) (spoiler alert):

1 to 100: 2 occurrences (123…141516…495051525354…)

101 to 200: 11 occurrences (115…150151152…158159…)

201 to 300: 1 occurrence (215)

301 to 400: 1 occurrence (315)

401 to 500: 1 occurrence (415)

501 to 600: 11 occurrences (501502…511512…515…521522…531532…541542…551552…561562…

571572…581582…591592…)

601 to 700: 1 occurrence (615)

701 to 800: 1 occurrence (715)

601 to 900: 1 occurrence (815)

901 to 1000: 1 occurrence (915)

1001 to 1100: 1 occurrence (1015)

1101 to 1200: 11 occurrences (1115…114911501151115211531154115511561157115811591160…)

1201 to 1300: 1 occurrence (1215)

1301 to 1400: 1 occurrence (1315)

1401 to 1500: 2 occurrences (1415…1500)

1501 to 1600: 100 occurrences (150015011502…15511552…15581559…15981599)

1601 to 1700: 1 occurrence: (1615)

1701 to 1800: 1 occurrence: (1715)

1801 to 1900: 1 occurrence: (1815)

1901 to 2000: 1 occurrence: (1915)

2001 to 2015: 1 occurrence: (2015)

public class Fifteen {

public static void main(String args[])
{
    char [] c = null; int fifteen_count=0; 
    StringBuilder s = new StringBuilder();
    for(int i=1;i<=2015;i++)
    {
        s.append(i);
        c= s.toString().toCharArray();

    }

    for(int j =0;j<c.length;j++)
    {

            if(c[j]=='5')
            {
                if(c[j-1]=='1')
                fifteen_count++;
            }


    }
    System.out.println(fifteen_count);
}

}

Ziad Skaik - 6 years, 6 months ago

Ok just to admit, I wrote a C++ program to double check my answer before I posted this problem :)

Wee Xian Bin - 6 years, 6 months ago

You mean to say that you did similar to what I did?

Ziad Skaik - 6 years, 6 months ago

@Ziad Skaik Just to confirm I had the correct answer before posting this :)

Wee Xian Bin - 6 years, 6 months ago
Vatsalya Tandon
Dec 13, 2014

Three steps and you get the answer-

  1. Create a computer program to print all numbers from 1 to 2015

    I created a JAVA program-

    public class Brilliant

{

void main()

{

    for(int i = 1 ; i<=2015; i++)

    {

        System.out.print(i);

    }

}

}

  1. Compile and Copy the Output.

  2. Paste the out put in "Notepad". Press Ctrl+F.

The number of times 15 comes is 152

And yes, Enjoy!

I enjoy the creative use of ctrl+f in this solution.

Brock Brown - 6 years, 5 months ago
Anna Anant
Dec 16, 2014

a = num2str([1:2015]); a(a==' ')=[]; s = 0;

for i = 1:length(a)-1 if [a(i) a(i+1)] == '15' s = s +1; i = i+1; end end s s = 152 Problem ??

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...