English   Japanese
Home   Site Map   Top   Prev.   Next   3-D ( 1   2   3   4   5 )   4-D ( 1   2   3   4   5   6 )

Algorithms to make pandiagonal magic cubes

[Order 8x] [Order 2x+1]

1. Algorithms for orders divisible by 8

   A pandiagonal magic cube of even order m can exist only if the order is divisible by 8, and an associated pandiagonal magic cube of even order can exist under the same condition. Also refer the page for Nasik magic cubes, which class is higher than pandiagonal.

1.1 Non-associated pandiagonal magic cubes (m = 8x)

A pandiagonal magic cube aijk of order m, where i,j,k = 0,...,m-1, is given by the following equation:
aijk = Tm(bijk) m2 + Tm(cijk) m + Tm(dijk) + 1,

where
Tm(x) = x (where x < m/2), 3m/2-1-x (otherwise)    (identical to the definition of Tm(x) for pantriagonal magic cubes).

The definitions of bijk, cijk, and dijk are as follows:
if i+j+k is even:
bijk = i + (m/4)j - (m/4+s)k   (mod. m),   0 <= bijk < m,
cijk = (m/4)i + j - (m/4+s)k   (mod. m),   0 <= cijk < m,
dijk = (m/4)i + (m/2)j + k   (mod. m),   0 <= dijk < m,

if i+j+k is odd:
bijk = -i - (m/4)j + (m/4+s)k + m/2   (mod. m),   0 <= bijk < m,
cijk = -(m/4)i - j + (m/4+s)k + m/2   (mod. m),   0 <= cijk < m,
dijk = (m/4)i + (m/2)j + k   (mod. m),   0 <= dijk < m,

where
s = -1 (if m-24 is divisible by 32), 1 (otherwise).

1.2 Associated pandiagonal magic cubes (m = 8x, m >= 8)

An associated pandiagonal magic cube can be constructed by a similar way to the algorithm for pantriagonal diagonal magic cubes. The only difference is the definition of the binary cube B[0]ijk:
B[0]ijk = {i0 + j2 + j0 + k2 + k0 + (j1+j0)(k1+k0)} mod 2.

A magic cube constructed by this algorithm is also 3D-compact.


Note There exists another algorithm for order >= 16.

(1) Case m = 16x

An associated pandiagonal magic cube aijk of order m, where i,j,k = 0,...,m-1, is given by the following equation:
aijk = Tm(bijk) m2 + Tm(cijk) m + Um(dijk) + 1,

where
Tm(x) = x (where x < m/2), 3m/2-1-x (otherwise),
Um(x) = x (if x < m/4 or x >= 3m/4), m-1-x (otherwise).
(identical to the definitions of Tm(x) and Um(x) for pantriagonal magic cubes)

The definitions of bijk, cijk, and dijk are as follows:
if i+j+k is even:
bijk = i + (m/4)j - (m/4+s)k   (mod. m),   0 <= bijk < m,
cijk = (m/4)i + j - (m/4+s)k   (mod. m),   0 <= cijk < m,
dijk = (m/4)i + (m/8)j + k + 3m/16   (mod. m),   0 <= dijk < m,

if i+j+k is odd:
bijk = -i - (m/4)j + (m/4+s)k + m/2   (mod. m),   0 <= bijk < m,
cijk = -(m/4)i - j + (m/4+s)k + m/2   (mod. m),   0 <= cijk < m,
dijk = (m/4)i + (m/8)j + k + 3m/16   (mod. m),   0 <= dijk < m,

where
s = -1 (if m-24 is divisible by 32), 1 (otherwise).

(2) Case m = 16x+8, m >= 24

An associated pandiagonal magic cube aijk of order m, where i,j,k = 0,...,m-1, is given by the following equation (aijk is also complete):
aijk = Tm(bijk) m2 + Tm(cijk) m + Um,4(dijk) + 1.

Tm(x) is already defined in the case of m = 16x. Um,4(x) is defined in the page for Nasik magic cubes.
The definitions of bijk, cijk, and dijk are as follows:
if i+j+k is even:
bijk = i + (m/4)j - (m/4+s)k   (mod. m),   0 <= bijk < m,
cijk = (m/4)i + j - (m/4+s)k   (mod. m),   0 <= cijk < m,
dijk = (m/4)i + (m/8)j + 4k + 3(m/8+1)/2   (mod. m),   0 <= dijk < m,

if i+j+k is odd:
bijk = -i - (m/4)j + (m/4+s)k + m/2   (mod. m),   0 <= bijk < m,
cijk = -(m/4)i - j + (m/4+s)k + m/2   (mod. m),   0 <= cijk < m,
dijk = (m/4)i + (m/8)j + 4k + 3(m/8+1)/2   (mod. m),   0 <= dijk < m,

where
s = -1 (if m-24 is divisible by 32), 1 (otherwise).

Back

2. Algorithms for odd orders

   A pandiagonal magic cube of odd order m can exist only if the order is higher by 6, and an associated pandiagonal magic cube of odd order can exist under the same condition.
The function gcd means the greatest common divisor.

2.1 Case m = 2x+1, m >= 7, and gcd(m, 3x5) = 1 (associated)

In this case, m is prime to both 3 and 5.
A pandiagonal magic cube aijk of order m, where i,j,k = 0,...,m-1, is given by the following equation:
aijk = bijk m2 + cijk m + dijk + 1,

where
bijk = i + 2j + 3k + {(m-1)/2+3}   (mod. m),   0 <= bijk < m,
cijk = i + 3j + 2k + {(m-1)/2+3}   (mod. m),   0 <= cijk < m,
dijk = 2i + 3j - k + {(m-1)/2+2}   (mod. m),   0 <= dijk < m.

2.2 Case m = 2x+1, m >= 7, and 1 < gcd(m, 3x5) < m (associated)

Let q be gcd(m, 3x5) and p be m/q. In this case, p > 1 and q > 1.
A pandiagonal magic cube aijk of order m, where i,j,k = 0,...,m-1, is given by the following equation:
aijk = Sm,q(bijk) m2 + Sm,q(cijk) m + Sm,q(dijk) + 1,

where
bijk = i + 2j + 3k + {(m-1)/2+3}   (mod. m),   0 <= bijk < m,
cijk = i + 3j + 2k + {(m-1)/2+3}   (mod. m),   0 <= cijk < m,
dijk = 2i + 3j - k + {(m-1)/2+2}   (mod. m),   0 <= dijk < m,
Sm,q(x) = Qp,q([x/q], x mod q),

where [x] means the integer part of x.

Qp,q(x, y), where 0 <= x < p and 0 <= y < q, is given by the following equations (identical to Qp,q(x, y) for Nasik magic cubes):
Qp,q(x, y) = qx + y (if 0 < x < p-1 and x is even),
qx + (q-1-y) (if 0 < x < p-1 and x is odd),
y/2 + (q-1)/2 (if x = 0 and y is even),
(y-1)/2 (if x = 0 and y is odd),
y/2 + (p-1)q (if x = p-1 and y is even),
(y-1)/2 + pq - (q-1)/2 (if x = p-1 and y is odd).

See the page for Nasik magic cubes to see examples of Qp,q(x, y) and Sm,q(x).

2.3 Case m = 2x+1, m >= 7, and gcd(m, 3x5) = m (associated)

In this case, always m = 15.
A pandiagonal magic cube aijk of order m, where i,j,k = 0,...,m-1, is given by the following equation:
aijk = S*(bijk) m2 + S*m(cijk) m + S*m(dijk) + 1,

where
bijk = i + 2j + 3k + {(m-1)/2+3}   (mod. m),   0 <= bijk < m,
cijk = i + 3j + 2k + {(m-1)/2+3}   (mod. m),   0 <= cijk < m,
dijk = 2i + 3j - k + {(m-1)/2+2}   (mod. m),   0 <= dijk < m,
S*15(x) = R3,5(x mod 3, x mod 5) - 1.

R3,5 is an order-(3,5) associated magic rectangle. For more information, see the page for Nasik magic cubes.

Back


Home   Site Map   Top   Prev.   Next   3-D ( 1   2   3   4   5 )   4-D ( 1   2   3   4   5   6 )

Mitsutoshi Nakamura (Feedback)    To send an email to me, please enable JavaScript on your browser.
[Legal indication] Prohibit the send of any spam or advertising.

This page was last updated on August 8, 2016.
"Magic Cubes and Tesseracts"   http://magcube.la.coocan.jp/magcube/en/
Copyright © 2004-2016, Mitsutoshi Nakamura. All rights reserved.

track feed Magic Cubes and Tesseracts RSS
SEO
loading
Magic Cubes and Tesseracts