Magic Numbers

Author(s): Dick Wagner
Publication: The Plotter
Pub Details: The Plotter v4 n10 (Volume 4, Issue 10)
Date: October 1986
Pages: 7

Combinations of numbers have interested mathematicions for hundreds of years, One such arrangement is called MAGIC SQUARE. There are also many such squares and all seem to be based on some math principal, A square is made up of rows and columns of numbers, This program asks for number of rows and columns (equal to make a square). Then the computer generates a square in which all rows and colums are equal when their numbers are added up, Sometimes the diagonals are also equal to the row or column sums,

This program is for the 1000 and 2068, The only difference is in line 200 where the up arrow means “to the power of” so ** is used with the other computers,

The print out is slow enough so you can see the sequence of numbers being printed,

  10 REM THERE MUST BE AN ODD NUMBER OF COLUMNS/ROWS
100 DIM M(9,9)
110 PRINT AT 10,0;"NUMBER OF COLUMNS/ROW ?"
115 INPUT N
120 CLS
130 IF N/2=INT (N/2) THEN GO TO 110
140 PRINT AT 0,0;" MAGIC NUMBERS";AT 1,0;" ROWS/COLUMNS."
150 REM
160 LET C1=0
170 LET C=INT (N/2)+1
180 LET R=1
185 LET C1=C1+1
190 PRINT AT R*2+1,C*3;C1
200 IF C1=INT (N^2) THEN GO TO 330
210 IF C1/N<>INT (C1/N) THEN GO TO 240
220 LET R=R+1
230 GO TO 185
240 LET C=C+1
250 IF C<=N THEN GO TO 290
260 LET C=1
270 LET R=R-1
280 GO TO 185
290 LET R=R-1
300 IF R>=1 THEN GO TO 185
310 LET R=N
320 GO TO 185
330 LET T=0
340 FOR I=1 TO N
350 LET T=T+M(I,1)
360 NEXT I
370 PRINT AT 0,0;T
375 STOP
380 COPY
390 PAUSE 250
400 LLIST
410 NEW
415 REM CHANGE LINE 420 FOR YOUR METHOD OF SAVE. THIS IS FOR MY DISK SYSTEM
420 SAVE /3
430 RUN

Transcription note: the listing is corrected. As printed, line 300 is COPY, inside the loop that places the numbers, so they overwrite one another and the square is not magic; replaced by IF R>=1 THEN GO TO 185.

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.