Magic squares of doubly even order: Difference between revisions

Content added Content deleted
(added a light blue grid (magic square) to the task section header.)
m (→‎{{header|REXX}}: added a comment to the REXX section header, added a comment to the CORN subroutine.)
Line 99: Line 99:
<!-- I couldn't figure out the other code's bit shifting and bit ANDing, so I wrote my own algorithm. -->
<!-- I couldn't figure out the other code's bit shifting and bit ANDing, so I wrote my own algorithm. -->


Marked numbers indicate that those (sequentially generated) numbers don't get 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*/
Line 127: Line 128:
return
return
/*──────────────────────────────────────────────────────────────────────────────────────*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
corn: do r=1 for n; if r>s & r<=n-s then iterate
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); end /*c*/
end /*r*/
end /*r*/