27 lines
655 B
Plaintext
27 lines
655 B
Plaintext
$NOPREFIX
|
|
|
|
DIM order AS INTEGER
|
|
DIM target AS INTEGER64
|
|
|
|
PRINT "First 20 magic constants:"
|
|
FOR i = 3 TO 22
|
|
PRINT USING "####, "; MagicSum(i);
|
|
IF i MOD 5 = 2 THEN PRINT
|
|
NEXT i
|
|
PRINT
|
|
PRINT USING "1000th magic constant: ##########,"; MagicSum(1002)
|
|
PRINT
|
|
PRINT "Smallest order magic square with a constant greater than:"
|
|
FOR i = 1 TO 13 ' 64-bit integers can take us no further, unsigned or not
|
|
target = 10 ^ i
|
|
DO
|
|
order = order + 1
|
|
LOOP UNTIL MagicSum(order) > target
|
|
PRINT USING "10^**: #####,"; i; order
|
|
order = order * 2 - 1
|
|
NEXT i
|
|
|
|
FUNCTION MagicSum&& (n AS INTEGER)
|
|
MagicSum&& = (n * n + 1) / 2 * n
|
|
END FUNCTION
|