0
$\begingroup$

How many times the number 25 is written if we list all the numbers from 1 to 100,000 ?

In this question, firstly I consider the set $\{0, 1, 2, 3, 4, 6, 7, 8, 9 \}$, find the number of sequence whose length 2,3,4 and 5 and it contains 25, and then multiplied it with 2 since I should also consider the set $\{0, 1, 3, 4, 5, 6, 7, 8, 9 \}$, which will give me the same number of different sequence, so I found the answer $5832$, but is there any problem with my logic ?, and how can I solve this question differently ?

I'm looking both for validation of my solution, and alternative solutions to this question.

  • 0
    I think it might be helpful to make the question more precise. What does it mean to "list all the numbers from 1 to 100000"? For example, if I write 1 2 3 4 ... 501 502 503... does that 25 that comes from the $2$ in $502$ and from the $5$ in $503$ count?2017-02-23
  • 1
    I'm not seeing as many as you see. For example, between the patterns $25xxx,x25xx,xx25x,xxx25$ there are only $4000$ and of course there is some double counting there. What pattern are you seeing that I am not counting?2017-02-23
  • 0
    @Anonymous No, as a single pair 25, i.e 42582017-02-23
  • 1
    Then the answer is just $4000$. I don't understand the method you use to count.2017-02-23

2 Answers 2

5

We may as well count the number of occurrences of the substring $25$ in the $100\,000$ five digit strings $00000-99999$. For each of the four possible positions of $25$ in a five digit string there are exactly $1000$ strings where this occurrence is counted. The answer to your question therefore is $4000$.

  • 0
    It is nice method, but do you have any idea what is the problem in my method ?2017-02-23
  • 1
    Python `print sum(str(n).count('25') for n in range(1,100000))` confirms the answer.2017-02-23
1

The answer of 4,000 you were given is correct.

You can't break the intervals the way you did because that changes the number of possible locations of the string/number "25".

Here is how I suggest you visualize the problem

You want to determine how many places the string/number "25" can occur in a 6 digit number restricted to 100,000.

100,000 gives you 6 digit places but, the string/number "25" cannot start in the first digit since the first digit is limited/restricted to "1". Therefore, the situation is as follows, using underscores for digit placeholders

1 _ _ _ _ _

The pair of digits "25" can only occur in the places shown below

1 _ _ _ 25
1 _ _ 25 _
1 _ 25 _ _
1 25 _ _ _

The above shows that the string/number "25" can only occupy 4 possible places.

Now, no matter where the string/number "25" is found there will be 3 digit placeholders left to fill in. Each of the digit placeholders can be filled in with 0 through 9, that is, 10 digits.

Therefore, the number of arrangements is 4 times 10x10x10 (permutation of 10 objects/digits 3 at a time, that is, 10^3), therefore, there are 4000 possible arrangements of the string/number "25" between 1 and 100,000.

Hopefully that helps you see why your method doesn't work.