Sunday Times Teaser 2694 – Impaired
by Angela Newing
A rod of length 40 centimetres is cut into six pieces, each of which has a length that is whole number of centimetres. The largest piece is twice the length of another piece.
There are no duplicate values in a list of the combined lengths of all possible pairs of pieces. There is only one duplicate value in a list of the combined lengths of all possible triplets of pieces.
What are the lengths of the pieces (in increasing order)?
One Comment
Leave one →
-
brian gladman permalink12345678910111213141516171819202122232425262728293031323334353637383940from itertools import combinations# a - a and 2 * a are the lengths of the two pre-cut pieces# r - the remaining length of the rod# p - the list of the lengths of pieces cut so far (without# the pre-cut pieces); the pieces are cut in order of# increasing length (4 pieces to give 6 in total)def solve(a, r, p):# the number of pieces yet to be cutn = 4 - len(p)if n > 1:# cut another piece off the rod (if n pieces remain to be# cut and x is the maximum length for the next one, then# x + ... + x + n - 1 <= r, hence hi = x + 1 is given by:hi = (r - n * (n - 3) // 2) // nfor x in range(p[-1] + 1 if p else 1, hi):solve(a, r - x, p + [x])else:# add the last piece and the two pre-cut piecesq = p + [r, a, 2 * a]# compute the combined lengths of all pairs of piecesv = [x + y for x, y in combinations(q, 2)]# check that these are all differentif len(v) == len(set(v)):# compute the combined lengths of all triplets of piecesw = [x + y + z for x, y, z in combinations(q, 3)]# check that there is only one duplicateif len(w) == len(set(w)) + 1:print(sorted(q))# all lengths are distinct since there would otherwise be# duplicate pair lengths; the length of the largest piece# is even and at least 10 since 8 is impossible for a rod# of length 40; 10 is the minimum sum of the lengths of 4# pieces so the lengths (x and 2.x) of the other 2 have a# maximum sum of 30for x in range(5, 11):solve(x, 40 - 3 * x, [])