On Fri, Nov 21, 2008 at 4:19 PM, Luther Fuller <
email@hidden> wrote:
But, what if we let d = 0? If we use the brute force script, we find that if
n = 6, then there are 488890 zeros in the print-out. Of course, the answer
is different in this case since leading zeros aren't printed.
Well, in an odometer, at least a traditional mechanical one, the
leading zeroes are there. But assume it's digital and leading zeroes
don't count. Then you have to construct a sum. Start with the same
total (n * 10^(n-1)).
1. Subtract any zeroes that appear in the high digit; there's one of
those for every possible value of the remaining digits, so that's
10^(n-1).
2. Subtract any zeroes in the second-to-highest digit that occur when
the high digit is zero: that's 10^(n-2).
Etc. Continue counting down and subtracting.
600000 - 100000 - 10000 - 1000 - 100 - 10 - 1 = 488889.
but then you have to add 1 back for the case where the total value is
0, even though that's technically a "leading" zero.
488889 + 1 = 488890.
So the general result is n * 10^(n-1) - [sum from 1 to n of 10^n] +
1. Of course, that middle number is just a sequence of '1's of length
n, easily written down directly when you know n:
600000 - 111111 + 1 = 488890.
--
Mark J. Reed <
email@hidden>