26 lines
732 B
Plaintext
26 lines
732 B
Plaintext
100 REM Magic constant
|
|
110 DECLARE EXTERNAL FUNCTION A
|
|
120 DECLARE EXTERNAL FUNCTION InvA
|
|
130 PRINT "The first 20 magic constants are";
|
|
140 FOR N = 1 TO 20
|
|
150 PRINT A(N);
|
|
160 NEXT N
|
|
170 PRINT
|
|
180 PRINT "The 1,000th magic constant is"; A(1000)
|
|
190 LET E = 1
|
|
200 FOR N = 1 TO 20
|
|
210 LET E = E * 10
|
|
220 PRINT "10^";
|
|
230 PRINT USING "##: #########": N, InvA(E)
|
|
240 NEXT N
|
|
250 END
|
|
260 REM Returns the magic constant of a magic square of order N + 2
|
|
270 EXTERNAL FUNCTION A(N)
|
|
280 LET N2 = N + 2
|
|
290 LET A = IP((N2 * ((N2 * N2) + 1)) / 2)
|
|
300 END FUNCTION
|
|
310 REM Returns the order of the magic square whose magic constant is at least X
|
|
320 EXTERNAL FUNCTION InvA(X)
|
|
330 LET InvA = IP((2 * X) ^ (1 / 3)) + 1
|
|
340 END FUNCTION
|