Each of the capital letters are substituted by a different digit from 0 to 9 in this 3x3 square such that the six sums formed by the leftmost column, rightmost column, top row, bottom row and the two main diagonals are each equal to x. Each of the remaining row and the remaining column may or may not sum to x.
A B C
D E F
G H I
Determine the respective minimum value and the maximum value of x.
There are 12 arrangements, not counting rotations/reflections.
The minimum x is 9 and the maximum x is 18.
The solutions shown below have A as the smallest corner and G > C so as to avoid the trivial variations. In the array below, the value of x is shown below the array. An * appears to the right of the bottom row of the array in the cases where it actually forms a magic square, where the middle row and the middle column each total to x.
081 091 092 093 183 192 285 294 385 546 647 657
765 876 753 852 642 876 741 753 642 321 321 432
243 253 416 417 507* 354 609 618* 709 708 809 819
9 10 11 12 12 12 15 15 16 15 17 18
DECLARE SUB place (row!, col!)
DIM SHARED used(9), bd(3, 3), x, minX, maxX, solCt
CLS
minX = 999
place 1, 1
PRINT : PRINT : PRINT minX; maxX, solCt
END
SUB place (row, col)
FOR i = 0 TO 9
IF used(i) = 0 THEN
good = 1
used(i) = 1
bd(row, col) = i
seq = 3 * (row - 1) + col
SELECT CASE seq
CASE 3
x = bd(1, 1) + bd(1, 2) + bd(1, 3)
IF i < bd(1, 1) THEN good = 0
CASE 7
IF x <> bd(1, 1) + bd(1, 2) + bd(1, 3) THEN good = 0
IF x <> bd(1, 3) + bd(2, 2) + bd(3, 1) THEN good = 0
IF x <> bd(1, 1) + bd(2, 1) + bd(3, 1) THEN good = 0
IF i < bd(1, 3) THEN good = 0
CASE 9
IF x <> bd(3, 1) + bd(3, 2) + bd(3, 3) THEN good = 0
IF x <> bd(1, 1) + bd(2, 2) + bd(3, 3) THEN good = 0
IF x <> bd(1, 3) + bd(2, 3) + bd(3, 3) THEN good = 0
IF i < bd(1, 1) THEN good = 0
END SELECT
IF good THEN
IF seq < 9 THEN
c = col + 1: r = row
IF c > 3 THEN c = 1: r = r + 1
place r, c
ELSE
FOR j = 1 TO 3
LOCATE j, solCt * 5 + 1
PRINT LTRIM$(STR$(bd(j, 1))); LTRIM$(STR$(bd(j, 2))); LTRIM$(STR$(bd(j, 3)));
NEXT
IF x <> bd(2, 1) + bd(2, 2) + bd(2, 3) THEN good = 0
IF x <> bd(1, 2) + bd(2, 2) + bd(3, 2) THEN good = 0
IF good THEN PRINT "*";
LOCATE j, solCt * 5 + 1
PRINT x;
solCt = solCt + 1
IF x < minX THEN minX = x
IF x > maxX THEN maxX = x
END IF
END IF
used(i) = 0
END IF
NEXT
END SUB
|
Posted by Charlie
on 2009-08-25 13:57:41 |