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

magiccube.2np1

Magic cubes of order 2n+1


Description

Creates odd-order magic cubes

Usage

magiccube.2np1(m)

Arguments

m

n=2m+1

Author(s)

Robin K. S. Hankin

References

website

See Also

Examples

#try with m=3, n=2*3+1=7:

m <-7                     
n <- 2*m+1


apply(magiccube.2np1(m),c(1,2),sum)
apply(magiccube.2np1(m),c(1,3),sum)
apply(magiccube.2np1(m),c(2,3),sum)

#major diagonal checks out:
sum(magiccube.2np1(m)[matrix(1:n,n,3)])

#now other diagonals:
b <- c(-1,1)
f <- function(dir,v){if(dir>0){return(v)}else{return(rev(v))}}
g <- function(jj){sum(magiccube.2np1(m)[sapply(jj,f,v=1:n)])}
apply(expand.grid(b,b,b),1,g)  #each diagonal twice, once per direction.

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.