New Scientist Enigma 967 – Prime Cubes
by Colin Singleton
From New Scientist #2122, 21st February 1998
George has 27 small blocks which have been identified with 27 different prime numbers — each block has its number on each face. He has assembled the blocks into a 3 x 3 x 3 cube,. On each of the three visible faces, the nine numbers total 320 — but this is not true of the three hidden faces.
George remembers that when he bought the blocks they were assembled into a similar 3Ă—3Ă—3 cube, but on that occasion they showed the same total on each of the six faces, this being the smallest possible total if each block has a different prime number.
What was the total on each face when George bought the blocks?
One Comment
Leave one →
-
Brian Gladman permalink12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364from itertools import combinations, islice, permutationsfrom number_theory import Primes# The sum of the visible cube faces (3.corners + 2.edges + faces)# is minimised by putting the smallest eight primes (except 2) at# the corners, the next twelve smallest primes at the edges and# the final six primes at the face centrespr = Primes().range()corners = set(islice(pr, 1, 9))edges = set(islice(pr, 12))faces = set(islice(pr, 6))# visible face sums = (3.corners + 2.edges + faces) / 6face_sum, r = divmod(3 * sum(corners) + 2 * sum(edges) + sum(faces), 6)assert r == 0# try top face cornersfor tc4 in combinations(corners, 4):# ... with top face edgesfor te4 in combinations(edges, 4):# ... and check that the top face centre value is possibleu = face_sum - sum(tc4) - sum(te4)if u not in faces:continue# the remaining edge and face valuesmb8 = edges.difference(te4)mbf = faces.difference([u])# try bottom face cornersbc4 = corners.difference(tc4)# ... with bottom face edgesfor be4 in combinations(mb8, 4):# ... and check that the bottom face centre value is possiblev = face_sum - sum(bc4) - sum(be4)if not v in mbf:continue# remaining edge and face values for the four middle facesme4 = mb8.difference(be4)mfv = mbf.difference([v])# orientate the top face valuesa = tc4[0]for b, c, d in permutations(tc4[1:], 3):for i, j, k, l in permutations(te4, 4):# orientate the bottom face valuesfor e, f, g, h in permutations(bc4):for m, n, o, p in permutations(be4):# orientate the edge values for the middle facesfor q, r, s, t in permutations(me4):f4 = (face_sum - sum ((a, b, e, f)) - sum((i, m, q, r)),face_sum - sum ((b, c, f, g)) - sum((j, n, r, s)),face_sum - sum ((c, d, g, h)) - sum((k, o, s, t)),face_sum - sum ((d, a, h, e)) - sum((l, p, t, q)))if set(f4) == mfv:print(f'face sums = {face_sum}, example (front) (centre) (back) values:')print(f"top layer: {(a, i, b)}, {(l, u, j)}, {(d, k, c)}")print(f"middle layer: {(q, f4[0], r)}, {(f4[3], 2, f4[1])}, {(t, f4[2], s)}")print(f"bottom layer: {(e, m, f)}, {(p, v, n)}, {(h, o, g)}")exit()