Home Up

Instructions Generator Applications Theory Algorithm Other Sites







The key concept in this implementation of magic hyper-cubes is representation.

There are two inputs to this algorithm:

Row Size: number of elements per row ("Order")
Dimensions: number of dimensions n the magic cube

These inputs determine the internal representation for each cell in the magic hyper-cube. In particular, each cell is represented by a n-tuple:

where each d is an integer in the range 0 through (Row_Size-1) and n is the number of dimensions in the magic cube. The algorithm places n-tuples into each cell in the hyper-cube so that each digit appears only once in any hyper-row.

It is easy to prove that this structure represents a magic hyper-cube: the sum of the individual digits for any hyper-row is always the same: SUM(0:ROW_SIZE-1).

Sums of cells within hyper-rows will remain identical if you add a constant to each cell. To aid visual representation, I have chosen to set the center cell of the hyper-cube to zero by subtracting a constant equal to (ROW_SIZE^DIMENSIONS-1)/2 from each cell. This illustrates symmetry by matching positive and negative integers in cells that are in symmetric positions with respect to the center cell. It also creates a property wherein the sum of the cells in any hyper-row is equal to zero.