Sunday Times Teaser 2702 – Problemblem
by H Bradley and C Higgins
A small rectangular flag is composed of three rectangular areas that are coloured red, green and blue and have sides that are all integer numbers of centimetres.
The green rectangle’s area and perimeter are respectively twice and one half those of the red rectangle.
The three digits of the blue rectangle’s area are the same as the digits of the flag’s area but in reverse order.
What is the area of the flag?
One Comment
Leave one →
-
brian gladman permalink123456789101112131415161718192021222324252627282930313233343536373839from number_theory import divisors# rectangle width height# red wr hr# green wg hg# blue wb hb# flag wf hf## (1) wg.hg = 2.wr.hr# (2) wr + hr = 2.(wg + hg)# (3) wr.hr + wg.hg + wb.hb = rev(wb.hb)# (4) wb.hb = 100.x + 10.y + z (defining digits x, y and z)## wr.hr + wg.hg = 3.wr.hr = rev(wb.hb) - wb.hb = 99.(z - x)## So wr.hr = 33.k for 1 <= k <= 8# wr * hr = 33 * k (see above)for k in range(1, 9):for hr in divisors(33 * k):wr = 33 * k // hr# wg * hg is twice wr * hrfor hg in divisors(66 * k):wg = 66 * k // hg# check the condition on the perimetersif 2 * (wg + hg) == wr + hr:# put these two rectangles side by side and work out# the width and height of the third rectangle needed# to make the three comnbined into a large rectangleif hr > hg:(wb, hb, wf, hf) = (wg, hr - hg, wg + wr, hr)else:(wb, hb, wf, hf) = (wr, hg - hr, wr + wg, hg)# check that the flag and blue areas are digit reversedif str(wb * hb)[::-1] == str(wf * hf):fs = 'The flag is {} cm^2 - flag {}, red {}, green {}, blue {}.'print(fs.format(wf * hf, (wf, hf), (wr, hr), (wg, hg), (wb, hb)))