# Put numbers to a star-shaped puzzle For users who can not see picture, see description below

   Put numbers 1,2,3,4,5,6,8,9,10,11,12,13,14 (1 to 14, without 7)
to each letter in such a way that the numbers in each row with 3 or 4
letters in all three directions, sum the same constant X

M
I J K L
F G H
B C D E
A

B+C+D+E = F+G+H = I+J+K+L = B+F+J+M = C+G+K = A+D+H+L = I+F+C+A = J+G+D = M+K+H+E

• I erase 7, and replace it with 14, because we cannot put numbers 1 to 13, to satisfy the puzzle. – Jamal Senjaya Aug 22 '16 at 5:48

This does it:

For a constant sum of $28$

         M                     3
I   J   K   L         9  10   8   1
F   G   H             2  14  12
B   C   D   E        13   6   4   5
A                    11

There may be other solutions beyond symmetry ...now to write some code

new code for all valid solutions up to symmetry

There are $4$ solutions up to symmetry, all of which have a constant sum of $28$, have $14$ in their centre, and have tips that sum to $14$ This code runs within the second

from itertools import combinations, permutations

def f():
numbers = [i for i in range(1,7)]+[i for i in range(8,15)]
for g in numbers:
woG = set(numbers)
for jd in combinations(woG, 2):
for j, d in permutations(jd):
woGJD = set(woG)
x = g + j + d
xMG = j + d
for fh in combinations(woGJD, 2):
for f, h in permutations(fh):
if f + h == xMG:
woGJDFH = set(woGJD)
for kc in combinations(woGJDFH, 2):
for k, c in permutations(kc):
if k + c == xMG:
woGJDFHKC = set(woGJDFH)
for ila in combinations(woGJDFHKC, 3):
for i, l, a in permutations(ila):
if i + l + j + k == x and a + d + h + l == x and a + c + f + i == x:
woGJDFHKCILA = set(woGJDFHKC)
m, e, b = woGJDFHKCILA
if m < l and m + e + k + h == x and b + c + d + e == x and b + f + j + m == x:
yield (m,i,j,k,l,f,g,h,b,c,d,e,a), x

def printStar(m,i,j,k,l,f,g,h,b,c,d,e,a):
print('''      {0:>2}
{1:>2}  {2:>2}  {3:>2}  {4:>2}
{5:>2}  {6:>2}  {7:>2}
{8:>2}  {9:>2}  {10:>2}  {11:>2}
{12:>2}'''.format(m,i,j,k,l,f,g,h,b,c,d,e,a))
Like so:
>>> for star, s in pre():
...     print(s)
...     printStar(*star)
...
28
3
6  13   5   4
2  14  12
10   9   1   8
11
28
2
5  13   6   4
3  14  11
10   8   1   9
12
28
1
5  12   8   3
4  14  10
11   6   2   9
13
28
1
6  11   9   2
4  14  10
12   5   3   8
13

previous slow, non-symmetry "naive" search

Yes there are other solutions beyond symmetry - this code will not be fast, but it produces others quite quickly that are not mere reflections and/or rotations:

from itertools import permutations

def f():
for m,i,j,k,l,f,g,h,b,c,d,e,a in permutations([i for i in range(1,7)]+[i for i in range(8,15)]):
x = b+c+d+e
if x == f+g+h and x == i+j+k+l and x == b+f+j+m and x == c+g+k and x == a+d+h+l and x == i+f+c+a and x == j+g+d and x == m+k+h+e:
yield (m,i,j,k,l,f,g,h,b,c,d,e,a), x

def printStar(m,i,j,k,l,f,g,h,b,c,d,e,a):
print('''      {0:>2}
{1:>2}  {2:>2}  {3:>2}  {4:>2}
{5:>2}  {6:>2}  {7:>2}
{8:>2}  {9:>2}  {10:>2}  {11:>2}
{12:>2}'''.format(m,i,j,k,l,f,g,h,b,c,d,e,a))
Starting off like so:
>>> for star, s in f():
...     print(s)
...     printStar(*star)
...
28
1
2   9  11   6
10  14   4
8   3   5  12
13
28
1
3   8  12   5
10  14   4
9   2   6  11
13
The second is isomorphic to the one I gave before, but the first is not.

• how do you approach it? – Numberknot Aug 22 '16 at 5:40
• @numberknot I just went for 28 and shuffled them around, nothing inspired :( – Jonathan Allan Aug 22 '16 at 5:43
• Well, there is a lot of structure in your solution. Odd numbers on the tips, even in the middle. Pairs that sum to 14 on opposite sides, with the single 14 in the middle. I wouldn't be surprised that if there are other solutions, they have the same properties, – Jaap Scherphuis Aug 22 '16 at 5:46
• @JaapScherphuis yeah - we can rotate and/or reflect this one at least! – Jonathan Allan Aug 22 '16 at 5:49
• @JaapScherphuis - found an hetero-morphic solution, opposite tips summing to 14 may be a necessary condition, but even in the middle is not. – Jonathan Allan Aug 22 '16 at 6:08