Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

strachey

Strachey's algorithm for magic squares


Description

Uses Strachey's algorithm to produce magic squares of singly-even order.

Usage

strachey(m, square=magic.2np1(m))

Arguments

m

magic square produced of order n=2m+1

square

magic square of order 2m+1 needed for Strachey's method. Default value gives the standard construction, but the method will work with any odd order magic square

Details

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.

Author(s)

Robin K. S. Hankin

See Also

Examples

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)))

magic

Create and Investigate Magic Squares

v1.5-9
GPL-2
Authors
Robin K. S. Hankin
Initial release
2018-09-14

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.