Sunday Times Teaser 2719 – Foursums
by H Bradley and C Higgins
A class were given four different non-zero digits and asked to construct rectangles whose sides (in centimetres) were two digit numbers that used all four of these digits.
The class managed to build both the smallest and the largest rectangles that were possible with the given set of digits and found that their areas differed by one half a square metre.
What were the four digits?
One Comment
Leave one →
-
brian gladman permalink123456789101112131415161718192021from itertools import combinations, permutations# pick the four digits to be usedfor c in combinations(range(1, 10), 4):# the minimum and maximum areas for these digitsmn, mx = None, None# permute the digitsfor p in permutations(c, 4):# and form the two sides of a rectanglea, b = 10 * p[0] + p[1], 10 * p[2] + p[3]# avoid duplicate solutionsif a < b:# update the minimum and maximum areas foundt = (a * b, a, b)mn = t if not mn or t[0] < mn[0] else mnmx = t if not mx or t[0] > mx[0] else mx# look for areas differing by one half of a square metreif mx[0] - mn[0] == 5000:print('Digits = {}, Rectangles = {} and {}.'.format(c, mn, mx))