How many 7's are there in the numbers from 1 to 999,999?
For example 17 has one 7 and 3707 has two. How many are there altogether? I could have said from 1 to 1,000,000. Think of the choice of 999,999 as a hint of sorts. Knowledge of combinatorics may get in the way. There is a complicated combinatoric, solution but a very simple one making use of symmetry, provided that you see the problem in the right way. You should be able to do the arithmetic in your head. After finding the number of 7’s, find the number of 0’s. It takes just a little bit more of work. If you are good at mental math, you could also do the arithmetic for the 0 count in your head.
Observing members:
0
Composing members:
0
17 Answers
6*1+5*6*9+4*15*(92)+3*20*(93)+2*15*(94)+1*6*(95)=R, and there should be R 0s from 0 to 999,999 so the number of 0 is R-1
I bet Lucky Guy would know the answer.
@wsxwh111 , You found the combinatoric solution for the number of 7’s. If you use your work to compute the value, you will see that the answer is in a rather simple form, which should suggest that there is an easier way of getting it. You are working with either leading blanks or leading 0’s. A key insight to the simpler solution is to make them leading 0’s.
530,000 give or take (mental)
Each digit will be a 7 1/10 of the time, or 100,000 times. There are 6 digits for a total of 600,000 7’s.
@Mariah , Nicely done. The numbers for each digit except for 0 will be 600,000. Can you figure how many 0’s there are?
Let me expand a little on what @Mariah said. If we go from 0 to 999,999, we have a million numbers. Add leading zeroes so every number has 6 digits. That will have no impact on the number of 7’s, but now everything is symmetric. Each of the digits from 0 to 9 will appear the same number of times. There are a total of one million numbers times 6 digits for 6 million digits. 7 will appear 1/10 of the time. 1/10 of 6 million is 600,000.
For those of you who have some familiarity with combinatorics, let me explain the reasoning behind what @wsxwh111 did. Again assume numbers from 0 to 999,999 with leading zeroes. If, for example, we wanted to know how many numbers have two 7’s we would multiply C(6,2) times the number of possibilities for the other four digits, each of which can be some number other than 7, so we get 9^4. To get the total number of 7’s for this case, multiply by 2, because we want to count each 7, giving 2xC(6,2)x9^4 = 2×15x(9)^4. The total number of 7’s for any number of 7’s is the sum from k=1 to 6 of k*C(n,k)*9^(6-k).
Regarding the zeroes question….
Take the 600,000 that would be the answer if we had leading zeroes. The first 9 numbers contribute 5 leading zeroes each – subtract 5*9. The next 90 contribute 4 – subtract 4*90. The next 900 contribute 3. And so on. The final result is 488,895. I kinda feel like I made a mistake. I’ll double check later.
Quite pleasing to be in the ball park with an instant mental calculation, shit…i’m good.
Double checked, I actually do think my first quick calculation above was correct.
@Mariah: That worked for me…clear, simple and direct.
@Mariah , Very close but not quite. The calculation is actually quite simple. We want to subtract the number of leading zeroes from 600,000. The 100,000 numbers from 0 to 99,999 have a 0 in the most significant place. The 10,000 numbers from 0 to 9,999 have a 0 in the next most significant place. Continuing, we get 600,000 – 111,111 = 488,889.
I also checked by writing Python code:
def CountZeros():
.......def zeros(x):
.......... sm=0
.......... while x != 0:
............. if x % 10 == 0:
................... sm += 1
............. x //= 10
....... .. return sm
….. return sum((zeros(i) for i in range(1,1000000)))
>>> CountZeros()
488889
Ah but you said from 1 to 999,999 in your original question, not from 0 to 999,999. I think that is where our discrepancy comes from if I’m not mistaken.
If the prize for a correct guess is not a Lamborghini, I will pass.
@Mariah , 1 to 999,999 is what I end up with. All six zeroes from 000000 are eliminated. Each of the 1’s in 111,111 includes a 0 from 000000. If you are familar with Python code, the program counts zeroes in range(1,1000000), which in Python translates to the numbers from1 to 999,999.
Answer this question