Place the numbers 1,2,3,4,5,6,7 and 8 one at each corner of a cube in such a way that the sum of the numbers on each of the 6 faces of the cube is the same.
In [29]:
import numpy as np
import itertools
from pprint import pprint
In [12]:
nums = np.array([1,2,3,4,5,6,7,8])
In [13]:
faces = [(5,6,7,0),
(1,3,5,7),
(1,2,3,4),
(2,4,6,0),
(3,4,7,0),
(1,2,5,6)]
In [14]:
for face in faces:
print(np.take(nums, face))
In [31]:
results = set()
for perm in itertools.permutations(nums):
sums = set()
for face in faces:
sums.add(sum(np.take(perm, face)))
if len(sums) == 1:
res = frozenset(frozenset(np.take(perm, face)) for face in faces)
if res not in results:
results.add(res)
pprint(res)
In [ ]: