strachey | R Documentation |
Uses Strachey's algorithm to produce magic squares of singly-even order.
strachey(m, square=magic.2np1(m))
m |
magic square produced of order |
square |
magic square of order |
Strachey's method essentially places four identical magic squares of order 2m+1 together to form one of n=4m+2. Then 0,n^2/4,n^2/2,3n^2/4 is added to each square; and finally, certain squares are swapped from the top subsquare to the bottom subsquare.
See the final example for an illustration of how this works, using a zero matrix as the submatrix. Observe how some 75s are swapped with some 0s, and some 50s with some 25s.
Robin K. S. Hankin
magic.4np2
,lozenge
strachey(3) strachey(2,square=magic(5)) strachey(2,square=magic(5)) %eq% strachey(2,square=t(magic(5))) #should be FALSE #Show which numbers have been swapped: strachey(2,square=matrix(0,5,5)) #It's still magic, but not normal: is.magic(strachey(2,square=matrix(0,5,5)))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.