|
魔方陣(4*N+2 魔方陣)
OPTION BASE 0
DIM A(30,30)
FOR N=6 TO 30 STEP 4
LET K = N * 2 - 2
FOR I = 1 TO N - 2
FOR J = 1 TO N-2
IF BITAND(I,2) = BITAND(J,2) THEN
LET K=K+1
LET A(I,J) = K
ELSE
LET K=K+1
LET A(N - 1 - I,N - 1 - J) = K
END IF
NEXT J
NEXT I
LET SUM = N * N + 1
LET A(0,0)=N-2
LET A(N - 1,N - 1) = SUM - (N-2)
LET A(0,N - 1)=N-1
LET A(N - 1,0) = SUM - (N-1)
LET A(0,N - 2) = SUM - 2 * N + 3
LET A(N - 1,N - 2) = SUM - (SUM-2*N+3)
LET A(N - 2,0)= 2 * N - 2
LET A(N - 2,N - 1) = SUM - (2*N-2)
FOR I = 1 TO N - 3
IF BITAND(I, 2) = 0 THEN LET J= 0 ELSE LET J= N - 1
LET A(J,I) = N - 2 - I
LET A(N - 1 -J,I) = SUM - (N-2-I)
LET A(I,J) = N - 1 + I
LET A(I,N - 1 -J) = SUM - (N-1+I)
NEXT I
PRINT N; " * "; N; " 魔方陣"
FOR I=0 TO N-1
FOR J=0 TO N-1
PRINT USING" ####":A(I,J);
NEXT J
PRINT
NEXT I
PRINT
NEXT N
END
|
|