[Problem & Solution]
PYRAMID
Place 8 of the integers from 1 to 10 on the edges of a pyramid such that the sum of the side values meeting at each corner is 16.
Python code:
"""
Top sides: a1 a2 a3 a4
Bottom sides: a5 a6 a7 a8
a1+a2+a3+a4=16
a1+a5+a8=16
a2+a5+a6=16
a3+a6+a7=16
a4+a7+a8=16
a5+a6+a7+a8 = 24
"""
from itertools import permutations
a = [1,2,3,4,5,6,7,8,9,10]
b = [True]*10
c24 = permutations(a,4)
d = []
for i in c24:
if i[0] + i[1] + i[2] + i[3] == 24:
b = [True]*10
for k in i:
b[k-1] = False
d = []
for m in range(10):
if b[m]:
d.append(m+1)
c16 = permutations(d,4)
for p in c16:
if p[0] + p[1] + p[2] + p[3] == 16:
if p[0]+i[0]+i[3]==16:
if p[1]+i[0]+i[1]==16:
if p[2]+i[1]+i[2]==16:
if p[3]+i[2]+i[3]==16:
print(i)
print(p)
print()
Info: All codes are written and solutions found by myself in this site.
Ali Eskici
13.10.2024