DECLARE SUB place (row#, col#)
CLEAR , , 25000
DEFDBL A-Z
DIM SHARED bd$(4, 4)
CLS
place 1, 2
END
SUB place (row, col)
s = 4 * (row - 1) + col
SELECT CASE s
CASE 2, 3, 5, 8, 9, 14
stVal = 1
CASE ELSE
stVal = 0
END SELECT
FOR n = stVal TO 9
bd$(row, col) = LTRIM$(STR$(n))
good = 1
SELECT CASE s
CASE 3, 8, 12, 15
sq = VAL(bd$(row, 1) + bd$(row, 2) + bd$(row, 3) + bd$(row, 4))
sr = INT(SQR(sq) + .5)
IF sr * sr <> sq AND row > 1 THEN good = 0
nxtRow = row + 1
IF nxtRow < 4 THEN nxtCol = 1: ELSE nxtCol = 2
CASE ELSE
nxtRow = row
nxtCol = col + 1
END SELECT
IF good THEN
SELECT CASE s
CASE 9, 14, 15, 12
sq = VAL(bd$(1, col) + bd$(2, col) + bd$(3, col) + bd$(4, col))
sr = INT(SQR(sq) + .5)
IF sr * sr <> sq THEN good = 0
END SELECT
IF good THEN
IF nxtRow > 4 THEN
FOR r = 1 TO 4
FOR c = 1 TO 4
PRINT RIGHT$(" " + bd$(r, c), 1);
NEXT
PRINT
NEXT
PRINT
ELSE
place nxtRow, nxtCol
END IF
END IF
END IF
NEXT n
END SUB
The above program does not verify that AB is not a square, and so produces:
25
2116
5184
64
25
2916
5184
64
71
2304
5929
64
Only in the last of the three is AB not a square.
Based upon Enigma No. 1555, "Not a square", by Richard England, New Scientist, 25 July 2009, page 26.
|