|
|
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)
woG.discard(g)
for jd in combinations(woG, 2):
for j, d in permutations(jd):
woGJD = set(woG)
woGJD.discard(j)
woGJD.discard(d)
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)
woGJDFH.discard(f)
woGJDFH.discard(h)
for kc in combinations(woGJDFH, 2):
for k, c in permutations(kc):
if k + c == xMG:
woGJDFHKC = set(woGJDFH)
woGJDFHKC.discard(k)
woGJDFHKC.discard(c)
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)
woGJDFHKCILA.discard(i)
woGJDFHKCILA.discard(l)
woGJDFHKCILA.discard(a)
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.
|