# (addition) 7 point star / heptagram Place the numbers $1$ through $14$ onto each point, so that:

1. A = 1

2. The sum of points in every line are equal,
(A+I+J+C = B+J+K+D = C+K+L+E = D+L+M+F = E+M+N+G = F+N+H+A = G+H+I+B)

3. A+B+C+D+E+F+G+1 = H+I+J+K+L+M+N

There is only one solution (if we rule out mirroring).

• sum of every line should be 30. – Gintas K Oct 3 '16 at 10:31
• I might be wrong, but I found no solutions. Can you kindly double-check that your equations are those intended? – Matsmath Oct 3 '16 at 11:46
• @Matsmath I brute forced it, and there are two solutions (one is the other mirrored), but I wasn't sure if we're supposed to brute force it. There isn't a no-computers tag, so I guess it's allowed, but it kinda feels like cheating... – Wu33o Oct 3 '16 at 11:48
• Thanks @Wu33o, I did something more intelligent, than brute-force (but apparently I made a mistake somewhere halfway through...) – Matsmath Oct 3 '16 at 11:50
• @matsmath Maybe you miss that a+..+g+1 = h+..+n. Not a+..+g = h+..+n – Jamal Senjaya Oct 3 '16 at 11:52

Ok, I started out trying to deduce the numbers, got stuck and decided to brute-force it since there's no tag. The solution is:

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

Still working on a more mathematical approach...

PS. Ugliest Python code I've ever written for who's interested:

a = 1
for b in range(2,15):
for c in range(2,15):
for d in range(2,15):
for e in range(2,15):
for f in range(2,15):
for g in range(2,15):
for h in range(2,15):
for i in range(2,15):
if g + h + i + b == 30:
for j in range(2,15):
if a + i + j + c == 30:
for k in range(2,15):
if b + j + k + d == 30:
for l in range(2,15):
if c + k + l + e == 30:
for m in range(2,15):
if d + l + m + f == 30:
for n in range(2,15):
if e + m + n + g == 30:
if f + n + h + a == 30:
x = [a, b, c, d, e, f, g, h, i, j, k, l, m, n]
if len(x) > len(set(x)):
break
if a + b + c + d + e + f + g + 1 == h + i + j + k + l + m + n:
print('a = ' + str(a))
print('b = ' + str(b))
print('c = ' + str(c))
print('d = ' + str(d))
print('e = ' + str(e))
print('f = ' + str(f))
print('g = ' + str(g))
print('h = ' + str(h))
print('i = ' + str(i))
print('j = ' + str(j))
print('k = ' + str(k))
print('l = ' + str(l))
print('m = ' + str(m))
print('n = ' + str(n))

• I am definitely interested! – Matsmath Oct 3 '16 at 12:17

Here is my python code which returns the same solutions as @Wu33o's:

import itertools

a = 1
for x in itertools.combinations(range(2,15),7):
for y in itertools.permutations(x):
(b,c,d,e,f,g,h) = y
if sum(y)-h==51:
i = 30-b-g-h
j = 30-a-c-i
k = 30-b-d-j
l = 30-c-e-k
m = 30-d-f-l
n1 = 30-e-g-m
n2 = 30-a-f-h
if n1==n2:
if tuple({b,c,d,e,f,g,h,i,j,k,l,m,n1})==tuple(range(2,15)):
print (a,b,c,d,e,f,g,h,i,j,k,l,m,n1)

• Can you make a comment on line if sum(y)-h==51:? – Matsmath Oct 3 '16 at 13:34
• Well, sum(y)=b+c+d+e+f+g+h, so sum(y)-h=b+c+d+e+f+g. As a=1, and 1+2+...+14=105, this line provides that a+b+c+d+e+f+g=52, and h+i+j+k+l+m+n=53. – elias Oct 3 '16 at 13:38
• You can unpack y in the for statement. You can also check condition 3 once for each combination rather than for each y. You could place your tuple of range in a variable so it does not construct it every time. Have a gander at my one (I also use sets). – Jonathan Allan Oct 3 '16 at 13:47

Here is a brute-force solution that works in less than a second:

from itertools import combinations, permutations
s = set(range(2,15))
for points in combinations(s,6):
if sum(points) == 51:
points = set(points)
for h,i,j,k,l,m,n in permutations(s-points):
c = 29 - j - i
f = 29 - h - n
e = 30 - c - k - l
g = 30 - e - m - n
d = 30 - l - m - f
b = 30 - j - k - d
if set((b,c,d,e,f,g)) == points:
b,c,d,e,f,g,h,i,j,k,l,m,n


It works by choosing all possible points (b,c,d,e,f,g) and checking that they sum to 51 (to satisfy the 3rd requirement that 1+a+b+c+d+e+f+g is half of the total of 1+all) then it traverses all permutations of the remaining inner points and evaluates what the values of all the points must be if the sums of some of the lines are 30, then checks that those cover the values of the points.

• how about points in combinations(s,5), and g being calculated as 51-sum(points), and checked if it is between 2 and 15? does that help speedup? – elias Oct 3 '16 at 13:51
• give it a go... – Jonathan Allan Oct 3 '16 at 14:03

I am posting this as a runner-up because this approach is somewhat faster than brute force.

The idea is to observe that the linear system of equations given above has a solution space of dimension 6. That is, if 6 (suitably chosen) parameters are defined (we specify, e.g. B=..., C=..., etc.), then the value of the remaining 13-6=7 (as A=1 was specified) parameters follow freely. This means that only all permutations of the 6-subsets of {2,3,...,14} should be inspected, which is a total of 6!*1716=1235520 cases. This is something managable by computers.

Thanks for @Wu33o for sharing their code, and help me to find a hole in my previous reasoning. Number-crunching would probably yield the same answer as posted above.