in reply to Ponder This: the worm-eaten page
This can also be solved by arithmetic quite readily.
The sum of the digits 1 .. 9 is 45.
Each digit appears 1000 times in each of the units, 10s, 100s and 1000s places.
The units always count as themselves: total 1000 * 45.
The tens are followed by a zero 1/10 of the time: total (100 + 900 * 10) * 45.
The hundreds are directly followed by a zero 1/10 of the time, and followed by a non-zero digit then a zero 1/10 of the remaining: total (100 + 90 * 10 + 810 * 100) * 45.
Similarly for the thousands: total (100 + 90 * 10 + 81 * 100 + 729 * 1000) * 45.
So the sum is (1300 + 1080 * 10 + 891 * 100 + 729 * 1000) * 45 = 830200 * 45 = 37,359,000
This approach can readily be adapted to base b, and beyond to the eat digits 0 .. x-1 required for part 2 of the puzzle.
Hugo
|
---|