Replace the letters in the diagram with a different number from 0 to 9, such that the sum of the four numbers on all edges are the same, and the sum of the three numbers on all three corners are the same.
A
B C
D E F
G H I J
In other words, A+C+F+J = A+B+D+G = G+H+I+J and
A+B+C = D+G+H = F+I+J.
There are several relationships involved. In addition to the given equations, these three, derived from those given, are useful:
B-H=C-I
D-C=H-F
F-B=I-D
That means that the contents of A,B,C,D and G determine all the rest:
H=A+B+C-G-D
F=H+C-D
I=C+H-B
J=A+B+C-F-I
and E is whatever is left over.
Trying all possibilities of A,B,C,D and G is easier than trying all possible permutations.
The following program goes through the possibilities, and then it prints out only those solutions where A>G>J, so that reflections and rotations are not considered as different:
CLS
FOR a = 0 TO 9
taken(a) = 1
FOR b = 0 TO 9
IF taken(b) = 0 THEN
taken(b) = 1
FOR c = 0 TO 9
IF taken(c) = 0 THEN
taken(c) = 1
FOR d = 0 TO 9
IF taken(d) = 0 THEN
taken(d) = 1
FOR g = 0 TO 9
IF taken(g) = 0 THEN
h = a + b + c - g - d
IF h >= 0 AND h <= 9 THEN
IF taken(h) = 0 THEN
taken(h) = 1
f = h + c - d
IF f >= 0 AND f <= 9 THEN
IF taken(f) = 0 THEN
taken(f) = 1
i = c + h - b
IF i >= 0 AND i <= 9 THEN
IF taken(i) = 0 THEN
taken(i) = 1
j = a + b + c - f - i
IF j >= 0 AND j <= 9 THEN
IF taken(j) = 0 THEN
taken(j) = 1
IF g + h + i = a + c + f AND c + f + j = b + d + g THEN
IF a > g AND g > j THEN
FOR e = 0 TO 9
IF taken(e) = 0 THEN EXIT FOR
NEXT
r0 = 5 * (ct \ 5): c0 = 10 * (ct MOD 5)
LOCATE r0 + 1, c0 + 5: PRINT STR$(a)
LOCATE r0 + 2, c0 + 4: PRINT STR$(b); STR$(c)
LOCATE r0 + 3, c0 + 3: PRINT STR$(d); STR$(e); STR$(f)
LOCATE r0 + 4, c0 + 2: PRINT STR$(g); STR$(h); STR$(i); STR$(j)
ct = ct + 1
END IF
END IF
taken(j) = 0
END IF
END IF
taken(i) = 0
END IF
END IF
taken(f) = 0
END IF
END IF
taken(h) = 0
END IF
END IF
END IF
NEXT
taken(d) = 0
END IF
NEXT
taken(c) = 0
END IF
NEXT
taken(b) = 0
END IF
NEXT
taken(a) = 0
NEXT
PRINT ct
The program finds:
5 5 6 7 7
1 7 6 2 0 4 1 3 1 5
6 2 4 1 3 9 5 8 2 2 8 5 6 0 3
4 3 9 0 4 8 4 0 2 3 7 1 5 4 6 0 3 4 8 2
7 8 8 8 8
6 0 0 5 2 3 2 4 2 4
1 4 8 6 2 3 1 4 7 3 0 6 6 1 5
3 9 3 2 3 4 9 1 7 5 6 0 6 5 7 1 1 7 9 0
8 8 8 9 9
2 6 2 6 4 3 0 4 0 6
4 1 7 7 0 4 1 2 9 2 6 5 5 1 3
7 5 9 0 4 5 9 3 7 7 6 0 8 3 7 1 8 2 8 4
9 9 9 9 9
1 3 1 4 2 4 3 0 3 1
2 4 6 3 2 6 3 1 7 1 5 6 0 5 7
6 5 7 0 6 5 8 0 6 6 8 0 4 7 4 2 7 6 4 2
9 9 9 9 9
3 2 3 2 3 4 3 5 5 1
0 4 8 1 4 8 2 0 8 4 0 7 0 2 8
8 6 5 1 6 7 6 0 8 6 7 1 7 6 8 2 8 7 3 4
--------
Thus there are 25 basic solutions, not counting rotations and reflections.
|
Posted by Charlie
on 2003-12-03 10:27:56 |