3
$\begingroup$

The question comes in two parts:

  1. For positive integers between 999 and 100 inclusive, how many contain the digit 5 at least once?

  2. For positive integers between 999 and 100 inclusive, how many contain the digit 5 exactly once?


Question 1

Numbers between 999 and 100 inclusive:

999 - 99 = 900

Numbers between 999 and 100 inclusive that do not contain digit 5:

8 * 9 * 9 = 648 (The 8 is because the first digit can't be 5 or 0)

Numbers that contain digit 5 at least once:

900 - 648 = 252


Question 2

Total numbers that contain digit 5 exactly once:

(1*9*9) + (8*1*9) + (8*9*1) = 225


I think I got it wrong but not sure which part.

$\endgroup$
  • 3
    $\begingroup$ Well, a good way to check is to count the number with exactly two $5's$. $55X$ gives us $9$, $5X5$ gives us $9$, $X55$ gives us $8$. Thus there are $9+9+8=26$ such numbers. Of course $555$ is the unique number in the range with three $5's$. We check that $252=225+26+1$ which seems like pretty good evidence that you are right. $\endgroup$ – lulu Nov 1 '18 at 16:34
  • $\begingroup$ @DavidG.Stork The OP is counting numbers with no digits equal to $5$ so that they can be subtracted from all three-digit positive integers. $\endgroup$ – N. F. Taussig Nov 1 '18 at 16:38
  • $\begingroup$ @DavidG.Stork OP is using a standard technique of counting how many numbers there are where we ignore the condition, giving $9\times 10\times 10 =900$ numbers in the range, and subtracting the number of numbers which violate the condition, violating the condition in this case meaning "does not have $5$ as a digit", there being $8\times 9\times 9$ such numbers, which will give the number of numbers that satisfy the condition as a result. $\endgroup$ – JMoravitz Nov 1 '18 at 16:38
  • $\begingroup$ @DavidG.Stork The purpose of that step is to get the number which does not contain digit 5 at all, which in this case is 648. My reasoning is that if I subtract 900 with 648, then all the remaining numbers would contain at least one digit 5. $\endgroup$ – potatoguy Nov 1 '18 at 16:40
  • $\begingroup$ "I think I got it wrong but not sure which part" Looks good to me. Do you have specific reason to doubt the answer? Be more confident, you seem to be doing well from what I can see. $\endgroup$ – JMoravitz Nov 1 '18 at 16:40
2
$\begingroup$

enter image description here

 There is one number with all three digits equal to 5.

 There are 1x10x10 = 100 numbers with the first digit equal to 5. 
 There are 9x1x10 = 90 numbers with the second digit equal to 5. 
 There are 9x10x1 = 90 numbers with the third digit equal to 5. 

 There are 10 numbers with the first and second digit equal to 5.
 There are 10 numbers with the first and third digit equal to 5.
 There are 9 numbers with the second and third digit equal to 5.

 There are 8x9x9 = 648 numbers with no digit equal to 5.

This is enough information to fill in the diagram above.

$\endgroup$
1
$\begingroup$

I got the same answers as you with the (javascript) code

var countFives = function(x){
    var count = 0;
    for (let c of x.toString(10)){
        if (c==="5") count++;
    }
    return count;
};

var s = 0;
for (let i=100; i<=999; i++) if (countFives(i)>=1) s++;
console.log(s);

252

var s = 0;
for (let i=100; i<=999; i++) if (countFives(i)===1) s++;
console.log(s);

225

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.