Brain-Teaser 524: [Digit sums]
From The Sunday Times, 27th June 1971 [link]
At a party at my friend Smith’s house recently, we were watching a rather attractive couple who were evidently enjoying each other’s company.
“I don’t know those two”, I said, “but I should be interested to know the lady’s age”.
“Well, I’m not the man to be explicit about that subject”, said Smith, “even though I know she’s rather proud of it. But her age is the sum of the digits in the sum of the digits in all the numbers from one to a hundred thousand inclusive”.
“Certainly not very explicit”, I said, “but then, how old is her companion?”
“Believe it or not”, said Smith, “but his age is the sum of the digits in the sum of the digits in all the numbers from one to a million inclusive”.
What was the difference between their ages?
This puzzle was originally published with no title.
[teaser524]
Jim Randell 9:26 am on 30 June 2020 Permalink |
It is not too onerous to tackle the problem directly using Python.
This program counts the digits in each of the required sequences. It runs in 405ms.
Run: [ @replit ]
from enigma import (fcompose, nsplit, irange, printf) # sum the digits in a number dsum = fcompose(nsplit, sum) # sum the digits of the numbers in a sequence dsums = lambda s: sum(map(dsum, s)) # age of the lady a1 = dsum(dsums(irange(1, 100_000))) # age of the gentleman a2 = dsum(dsums(irange(1, 1_000_000))) printf("a1={a1} a2={a2}, diff={d}", d=abs(a1 - a2))Solution: They are the same age, so the difference is 0.
But it is also fairly straightforward so solve analytically:
If we suppose DS(k) is the sum of the digits in the integers (represented in base 10), starting from 0, that are less than k, then:
The sum of the digits in 0 .. 9 is 45.
If we then consider numbers from 0 .. 99, the units digits comprise 10 lots of DS(10), and the tens digits comprise another 10 lots of DS(10):
For the digits from 0 .. 999, the tens and units digits together comprise 10 lots of DS(100), and the hundreds digits comprise 100 lots of DS(10).
Carrying on this construction we find:
(See: OEIS A034967 [ @oeis ]).
The sums we are interested in are therefore:
The extra 0 at the beginning doesn’t make any difference, but we need to add in the digits for the end points, which are both powers of 10, so only contribute an extra 1.
So we are interested in the digit sums of 2,250,001 and 27,000,001, both of which are 10.
So both ages are 10, and their difference is 0.
LikeLike