Teaser 3145: Easier to ask the audience
From The Sunday Times, 1st January 2023 [link] [link]
“I have forgotten the phone number!”, complained Martha, about to phone a friend. “So have I!”, replied George, “but I have some vague memories of it. It is a perfect square with all the digits different, and the last digit is equal to the number of digits to be dialled. The last-but-one digit is odd and one of the digits is zero. Also the second and third and last-but-one digits are all exact multiples of the first digit. Maybe you can work it out”.
Martha proceeded to dial the number correctly.
What number did she dial?
Happy New Year from S2T2!
[teaser3145]
Jim Randell 4:47 pm on 30 December 2022 Permalink |
The final digit of the square number tells us how long it is, so we only need to check up to 9 digits, and it must have a “second”, “third”, and “last-but-one” digit, so (assuming these are all different) there need to be at least 5 digits. And to also fit a 0 digit in there must be at least 6 digits.
And a perfect square cannot end with 7 or 8, so we only need to consider 6 or 9 digit numbers.
This Python program just tries all candidate squares in this range (and we could add further analysis to reduce the number of candidates).
It runs in 122ms. (Internal run time is 23.3ms).
Run: [ @replit ]
Solution: The number is: 173056.
173056 = 416².
LikeLike
Jim Randell 10:37 pm on 31 December 2022 Permalink |
With a bit of analysis we see that a 6-digit square must be of the form 1xx0x6, and so is the square of a number in the range [351, 445] that ends in the digit 4 or 6.
And a 9-digit square must be of the form 1xxxxxxx9, and so is the square of a number in the range [11093, 13698] that ends in the digit 3 or 7. (Thanks to Frits for correcting my upper bound).
This Python program just checks these numbers.
It runs in 52ms. (Internal runtime is 1.2ms).
Run: [ @replit ]
LikeLike
Frits 11:07 am on 1 January 2023 Permalink |
@Jim, I came to the same conclusion but with ranges [351-445] (you probably had a typo) and [11093-13698].
LikeLike
Jim Randell 11:16 am on 1 January 2023 Permalink |
Thanks. Yes, the upper bound should be 13698.
LikeLike
Tony Smith 2:17 pm on 1 January 2023 Permalink |
The only squares with odd penultimate digits have last digit 6.
LikeLike
Jim Randell 2:21 pm on 1 January 2023 Permalink |
Neat. So we only need to check 9 cases:
LikeLike
Frits 3:25 pm on 1 January 2023 Permalink |
@Jim, the check(irange(354, 444), step=10) is still needed.
LikeLike
Jim Randell 9:19 pm on 1 January 2023 Permalink |
Right. Still, it is only 19 cases to check. Easy enough to do on a pocket calculator.
LikeLike
Jim Randell 2:10 pm on 2 January 2023 Permalink |
Here is a version that uses less brute force (and less analysis).
The final two digits of the square number depend only on the final two digits of its root, so we can consider possible values for these 2 digits, and find those that give acceptable final two digits of the square. The final digit must corresponding to the digit length of the square, and then penultimate digit must be odd.
We then know the length of the square, final two digits and the leading digit must be a divisor of the penultimate digit, so we can consider possible roots that give the required conditions.
In the end we only need to apply the remaining tests on a handful of values.
This Python program runs in 51ms. (Internal runtime is 368µs).
Run: [ @replit ]
LikeLiked by 1 person
GeoffR 10:25 am on 31 December 2022 Permalink |
LikeLike
GeoffR 11:32 am on 2 January 2023 Permalink |
This solution uses previous postings in that the telephone number is six or nine digits long and the possible ranges of square values.
LikeLike
GeoffR 5:20 pm on 2 January 2023 Permalink |
This program checks for a 6-digit solution only.
No 9-digit solution was found in previous programs.
LikeLike