Teaser 2808: Hot stuff
From The Sunday Times, 17th July 2016 [link] [link]
George and Martha are dabbling in the world of high temperature physics. George was measuring the temperature of a molten metal and wrote down the result. He thought this was in degrees Centigrade and so he converted it to Fahrenheit. However, Martha pointed out that the original result was already in degrees Fahrenheit and so George converted it to Centigrade. Martha wrote down the original result and each of George’s two calculated answers. She noted that they were all four-figure numbers and that their sum was palindromic.
What was the original four-figure result?
[teaser2808]
Jim Randell 9:57 am on 10 August 2021 Permalink |
This Python program considers possible 4-digit numbers for the first reading, and then looks for viable second and third numbers that give a palindromic sum. It runs in 55ms.
Run: [ @replit ]
from enigma import (div, irange, is_npalindrome, printf) # convert centigrade (celsius) to fahrenheit c2f = lambda n: div(9 * n + 160, 5) # convert fahrenheit to centigrade (celsius) f2c = lambda n: div(5 * n - 160, 9) # original number (a 4-digit number) for n1 in irange(1000, 9999): # second number n2 = c2f(n1) if n2 is None or n2 < 1000 or n2 > 9999: continue # third number n3 = f2c(n1) if n3 is None or n3 < 1000 or n3 > 9999: continue # look for a palindromic sum t = n1 + n2 + n3 if is_npalindrome(t): # output solution printf("n1={n1} n2={n2} n3={n3} t={t}")Solution: The original reading was 3155.
And:
With analysis we can restrict the numbers considered for
n1, and simplify the calculations.We see
n1must be in the range [1832, 5537], and must be a multiple of 5, and must equal 5 (mod 9).Run: [ @replit ]
from enigma import (irange, is_npalindrome, printf) # all three numbers have 4 digits for k in irange(41, 122): # original number n1 = 45 * k + 5 # second number n2 = 81 * k + 41 # third number n3 = 25 * k - 15 # look for a palindromic sum t = n1 + n2 + n3 if is_npalindrome(t): # output solution printf("n1={n1} n2={n2} n3={n3} t={t}")LikeLike
GeoffR 11:55 am on 10 August 2021 Permalink |
Checking for the palindromic sum was a bit lengthy in MiniZinc, as I could not be sure if this total was four or five digits long.
LikeLike