magic.constant {magic} | R Documentation |
Returns the magic constant: that is, the common sum for all rows, columns and (broken) diagonals of a magic square
magic.constant(n,d=2,start=1)
n |
Order of the square |
d |
Dimension of square, defaulting to d=2 (a square) |
start |
Start value of square. Common values are 0 and 1. |
If n
is an integer, interpret this as the order of the square
or hypercube; return n(start+n^d-1)/2.
If n
is a square or hypercube, return the magic constant for
a normal array (starting at 1) of the same dimensions as n
.
Robin K. S. Hankin
magic.constant(4)