1 2 3 4 5 6 7 8 9 1 0 1 1 1 2 1 3 1 4 1 5 … 2 0 1 3 2 0 1 4 2 0 1 5 Calculate the total number of occurrences where ‘15’ appears in the whole number.
A person writes the numbers 1 to 2015 together as
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.
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! :)
it is true
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);
}
}
Ok just to admit, I wrote a C++ program to double check my answer before I posted this problem :)
You mean to say that you did similar to what I did?
@Ziad Skaik – Just to confirm I had the correct answer before posting this :)
Three steps and you get the answer-
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);
}
}
}
Compile and Copy the Output.
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.
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 ??
Problem Loading...
Note Loading...
Set Loading...
Done with four lines of Python: