Function Repository Resource:

MagicCube

Source Notebook

Generate a magic cube

Contributed by: Aster Gal

ResourceFunction["MagicCube"][n]

generates a magic cube of rank n.

Details and Options

A magic cube is an n×n×n cubical array of the numbers 1,2,,n3, arranged so that the sum of the numbers in a row, column, pillar, or space diagonal is constant.
The argument n must be an integer greater than 2.

Examples

Basic Examples (1) 

Generate a magic cube of rank 3:

In[1]:=
ResourceFunction["MagicCube"][3]
Out[1]=

Applications (2) 

Visualize a magic cube of rank 9:

In[2]:=
Image3D[Rescale[ResourceFunction["MagicCube"][9]]]
Out[2]=

You can see the magic property using grayscale:

In[3]:=
draw3D[array_] := Graphics3D[Raster3D@Rescale@array, Boxed -> False];
GraphicsGrid[
 Partition[Table[draw3D@ResourceFunction["MagicCube"][n], {n, 3, 20}],
   4], ImageSize -> Medium]
Out[4]=

Publisher

Aster Ctor (MoeNet)

Version History

  • 1.0.0 – 19 November 2019

Related Resources

Author Notes

Three-dimensional magic cubes can be divided into three types: odd rank, even rank and doubly-even rank.

License Information