Sunday Times Teaser 2886 – Metal Arithmetic
by Stephen Hogg
Published January 14 2018 (link)
The area of one face of a hot, steel cuboid block was a single-figure whole number of square feet; and it was within one per cent of this after cooling and contraction. When cool, it was cut, parallel to this face, into blocks of the same width and height, but unequal length. For the first cut block, its width, height and length, in inches, were different two-figure whole numbers with only four factors (including 1 and the number), and they had only the factor 1 in common. The same applied to the other cut blocks. Curiously, the six digits of the width, height and length of the first cut block were also all different.
In ascending order, what were the dimensions, in inches, of the shortest block?
-
Brian Gladman permalink1234567891011121314151617181920212223242526272829303132333435363738from itertools import combinationsfrom math import ceilpr = {2, 3, 5, 7}pr |= {x for x in range(11, 100, 2) if all(x % p for p in pr)}# the width, height and length of all cut blocks are all two# digit semi-primes - map these numbers to their two primesnf4 = {p * q:{p, q} for p, q in combinations(pr, 2) if 10 <= p * q < 100}# consider pairs of different semi-primes for the width and height when coldfor w, h in combinations(sorted(nf4.keys()), 2):# compute the area of the face when coldarea = w * h# the area when hot is the next higher single digit multiple of a square# foot such that the area when cold differs from it by less than 1%hot_sqft = 144 * ceil(area / 144)if 0.99 * hot_sqft < area < hot_sqft < 1440:# the width and height are different semi-primes with different digitsif not nf4[w] & nf4[h]:s4 = set(divmod(w, 10) + divmod(h, 10))if len(s4) == 4:# now consider lengths that do not share semi-primes with the width# and height, at least one of which doesn't share digits eitherl_vals, diff_digits_flag = set(), Falsefor l in nf4.keys():if not (nf4[w] | nf4[h]) & nf4[l]:diff_digits_flag |= not s4.intersection(divmod(l, 10))l_vals.add(l)# there are at least three blocks ('other blocks' is plural)if len(l_vals) > 2 and diff_digits_flag:f = 'The dimensions of the shortest block are {}" x {}" x {}".'print(f.format(*sorted((w, h, min(l_vals)))))