Magic squares of doubly even order: Difference between revisions

Content added Content deleted
m (→‎{{header|REXX}}: added a comment, changed whitespace, used a template for the output section.)
Line 2,116: Line 2,116:
<br>swapped &nbsp; (and thusly, stay in place in the magic square).
<br>swapped &nbsp; (and thusly, stay in place in the magic square).
<lang rexx>/*REXX program constructs a magic square of doubly even sides (a size divisible by 4).*/
<lang rexx>/*REXX program constructs a magic square of doubly even sides (a size divisible by 4).*/
n=8; s=n%4; L=n%2-s+1; w=length(n**2) /*size; small sq; low middle; # width*/
n= 8; s= n%4; L= n%2-s+1; w= length(n**2) /*size; small sq; low middle; # width*/
@.=0; H=n%2+s /*array default; high middle. */
@.= 0; H= n%2+s /*array default; high middle. */
call gen /*generate a grid in numerical order. */
call gen /*generate a grid in numerical order. */
call diag /*mark numbers on both diagonals. */
call diag /*mark numbers on both diagonals. */
Line 2,139: Line 2,139:
do c=1 for n; if @.r.c<0 then iterate; call max# /*find max number.*/
do c=1 for n; if @.r.c<0 then iterate; call max# /*find max number.*/
parse value -@.a.b (-@.r.c) with @.r.c @.a.b /*swap two values.*/
parse value -@.a.b (-@.r.c) with @.r.c @.a.b /*swap two values.*/
end /*c*/
end /*c*/
end /*r*/
end /*r*/; return
return
/*──────────────────────────────────────────────────────────────────────────────────────*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
corn: do r=1 for n; if r>s & r<=n-s then iterate /*"corner boxen", size≡S*/
corn: do r=1 for n; if r>s & r<=n-s then iterate /*"corner boxen", size≡S*/
do c=1 for n; if c>s & c<=n-s then iterate; @.r.c=-@(r,c); end /*c*/
do c=1 for n; if c>s & c<=n-s then iterate; @.r.c= -@(r,c) /*negate*/
end /*r*/
end /*c*/
return</lang>
end /*r*/; return</lang>
'''output''' &nbsp; when using the default input:
{{out|output|text=&nbsp; when using the default input:}}
<pre>
<pre>
1 2 62 61 60 59 7 8
1 2 62 61 60 59 7 8