Teaser 3155: Increasing temperature
From The Sunday Times, 12th March 2023 [link] [link]
I have written down an above-freezing temperature, a whole number of degrees Celsius, in which the digits are all different and are in decreasing order. I have then calculated the Fahrenheit equivalent. It is also a whole number whose digits are all different, but here the digits are in increasing order.
If I told you the first digit of the Celsius temperature, then you would not be able to calculate the temperature. However, bearing that in mind, if I now told you the final digit of the Celsius temperature, then it would be possible to calculate it.
You should now be able to work out the Celsius and Fahrenheit temperatures.
What are they?
[teaser3155]
Jim Randell 12:02 pm on 11 March 2023 Permalink |
This Python program runs in 56ms. (Internal runtime is 3.4ms).
Run: [ @replit ]
from enigma import ( irange, subsets, nconcat, div, nsplit, tuples, filter_unique, join, printf ) # generate temperatures (C, F) with C digits in decreasing order, # F digits in decreasing order, return the digits of (C, F) def generate(): # make the C temperature for cs in subsets(irange(9, 0, step=-1), min_size=1, select='C'): C = nconcat(cs) if C == 0: continue # convert to Fahrenheit F = div(9 * C + 160, 5) if F is None: continue # check digits are in increasing order fs = nsplit(F) if not all(a < b for (a, b) in tuples(fs, 2)): continue # return (C, F) temperatures printf("[C={C} F={F}]") yield (cs, fs) # collect possible temperatures ss = list(generate()) # selection function for the i'th digit of (C, F) digit = lambda i, k: (lambda x: x[i][k]) # we cannot work out the temperature knowing the first digit of C ss = filter_unique(ss, digit(0, 0)).non_unique # but now we can work it out knowing the last digit of C ss = filter_unique(ss, digit(0, -1)).unique # output solution for (C, F) in ss: printf("answer: C={C} F={F}", C=join(C), F=join(F))Solution: The temperatures are: 75 C and 167 F.
In total there are 7 possible temperatures:
(As F = (9/5)C + 32, only C temperatures that are divisible by 5 can have a corresponding F temperature that is an integer, so the last digit of a C temperature will always be 0 or 5).
The only temperatures that cannot be determined from the first digit are those beginning with 7, i.e.: 70, 75, 730, 7520.
And of these there is only one that ends in 5, i.e.: 75, and so this gives us the required answer.
LikeLike