 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 pantriagonal magic cubes

[Order 4x][Order 2x+1] [Order 4x+2]

## 1. Algorithms for orders divisible by 4

A pantriagonal magic cube can exist for any order divisible by 4. An associated pantriagonal magic cube can exist under the same condition. If the order is higher than 4, there exists a pantriagonal diagonal magic cube, which satisfies a stronger condition than pantriagonal. Furthermore, if the order is divisible by 8, there exists a Nasik magic cube, which satisfies a stronger condition than pantriagonal diagonal.

### 2.1 Non-associated pantriagonal magic cubes (m = 4x) (also complete and 2D-compact)

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

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

This cube is expressed as follows by the XmlHypercube format by Aale de Winkel:
for m = 4:
LP({1,2,2},{2,1,2},{2,2,1})= [0,1,3,2]
for m = 8:
LP({1,2,2},{2,1,2},{2,2,1})= [0,1,2,3,7,6,5,4]
In general:
LP({1,m/2,m/2},{m/2,1,m/2},{m/2,m/2,1})= [0,...,m/2-1,m-1,...,m/2] Back

### 2.2 Associated pantriagonal magic cubes (m = 4x)

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

where
bijk = 2hm/2(k mod m/2) + rm(i, k)   (if [4i/m] + j + [2k/m] is even),   m - 1 - {2hm/2(k mod m/2) + rm(i, k)}   (otherwise),
cijk = (i + j + k) mod m   (if k is even),   {m/2 - 3 - (i + j + k)} mod m   (otherwise),
dijk = (-i + j + k) mod m,

Tm(x) = x (where x < m/2), 3m/2-1-x (otherwise)    (identical to the definition for non-associated cubes).
Um(x) = x (if x < m/4 or x >= 3m/4), m-1-x (otherwise),
hm/2(x) = x (if x < m/4), m/2-1-x (otherwise),
rm(x, y) = 0 (if [2x/m + 1/2] + [2y/m + 1/2] is even), 1 (otherwise).

The following is an example for m = 4:

bijk
 0 3 0 3 2 1 2 1 1 2 1 2 3 0 3 0
 1 2 1 2 3 0 3 0 0 3 0 3 2 1 2 1
 2 1 2 1 0 3 0 3 3 0 3 0 1 2 1 2
 3 0 3 0 1 2 1 2 2 1 2 1 0 3 0 3

cijk
 0 1 2 3 1 2 3 0 2 3 0 1 3 0 1 2
 2 1 0 3 1 0 3 2 0 3 2 1 3 2 1 0
 2 3 0 1 3 0 1 2 0 1 2 3 1 2 3 0
 0 3 2 1 3 2 1 0 2 1 0 3 1 0 3 2

T4(cijk)
 0 1 3 2 1 3 2 0 3 2 0 1 2 0 1 3
 3 1 0 2 1 0 2 3 0 2 3 1 2 3 1 0
 3 2 0 1 2 0 1 3 0 1 3 2 1 3 2 0
 0 2 3 1 2 3 1 0 3 1 0 2 1 0 2 3

dijk
 0 1 2 3 3 0 1 2 2 3 0 1 1 2 3 0
 1 2 3 0 0 1 2 3 3 0 1 2 2 3 0 1
 2 3 0 1 1 2 3 0 0 1 2 3 3 0 1 2
 3 0 1 2 2 3 0 1 1 2 3 0 0 1 2 3

U4(dijk)
 0 2 1 3 3 0 2 1 1 3 0 2 2 1 3 0
 2 1 3 0 0 2 1 3 3 0 2 1 1 3 0 2
 1 3 0 2 2 1 3 0 0 2 1 3 3 0 2 1
 3 0 2 1 1 3 0 2 2 1 3 0 0 2 1 3

Here is the order-4 associated pantriagonal magic cube constructed by these bijk, T4(cijk), and U4(dijk). Back

## 2. Algorithms for odd orders

A pantriagonal magic cube of odd order can exist only if the order is higher than 4. An associated pantriagonal magic cube of odd order can exist under the same condition. If the order is higher than 8, there exists a Nasik magic cube, which satisfies a stronger condition than pantriagonal.

### 2.1 When the order m is NOT divisible by 3 (m = 2x+1, m >= 5) (associated)

An associated pantriagonal 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 = 2i + j + k + (m+3)/2   (mod. m),   0 <= bijk < m,
cijk = 2i - j + k + (m+1)/2   (mod. m),   0 <= cijk < m,
dijk = 2i + j - k + (m+1)/2   (mod. m),   0 <= dijk < m.

### 2.2 When the order m is divisible by 3 (m = 2x+1, m >= 5) (associated)

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

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

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). Back

## 3. Algorithms for singly-even orders

A pantriagonal magic cube exists for any singly-even (even but not divisible by 4) order higher than 4. An associated pantriagonal magic cube of singly-even order also exists under the same condition.

### 3.1 Non-associated pantriagonal magic cubes (m = 4x+2, m >= 6) (also complete)

A pantriagonal magic cube aijk of order m, where i,j,k = 0,...,m-1, is given by the following equations (aijk is also complete):
aijk = a*ijk (if [2i/m]+[2j/m]+[2k/m] is even),
m3 + 1 - a*ijk (if [2i/m]+[2j/m]+[2k/m] is odd),
a*ijk = Fm(bijk, qijk) (m/2)2 + cijk (m/2) + dijk + 1,

where
bijk = i + j + k   (mod. m/2),   0 <= bijk < m/2,
cijk = i - j + k   (mod. m/2),   0 <= cijk < m/2,
dijk = i + j - k   (mod. m/2),   0 <= dijk < m/2,
Fm(x, y) = x + y (if x = m/2-2 or x is even),
4(x+1) - y - 1 (if x < m/2-2 and x is odd),
4(x+2) - y - 2 (if x = m/2-1),
qijk = 2[2i/m] + [2j/m] (if k < m/2),
3 - 2[2i/m] - [2j/m] (if k >= m/2).

The following tables are examples of Fm(x, y), Fm(bijk, qijk), a*ijk, and aijk for m = 6:
F6(x, y)
0123
00123
14567
21412108

F6(bijk, qijk)
 0 4 14 1 5 12 4 14 0 5 12 1 14 0 4 12 1 5 2 6 10 3 7 8 6 10 2 7 8 3 10 2 6 8 3 7
 4 14 0 5 12 1 14 0 4 12 1 5 0 4 14 1 5 12 6 10 2 7 8 3 10 2 6 8 3 7 2 6 10 3 7 8
 14 0 4 12 1 5 0 4 14 1 5 12 4 14 0 5 12 14 10 2 6 8 3 7 2 6 10 3 7 8 6 10 2 7 8 3

 3 7 8 2 6 10 7 8 3 6 10 2 8 3 7 10 2 6 1 5 12 0 4 14 5 12 1 4 14 0 12 1 5 14 0 4
 7 8 3 6 10 2 8 3 7 10 2 6 3 7 8 2 6 10 5 12 1 4 14 0 12 1 5 14 0 4 1 5 12 0 4 14
 8 3 7 10 2 6 3 7 8 2 6 10 7 8 3 6 10 2 12 1 5 14 0 4 1 5 12 0 4 14 5 12 14 4 14 0

a*ijk
 1 44 132 10 53 114 41 129 7 50 111 16 135 4 38 117 13 47 19 62 96 28 71 78 59 93 25 68 75 34 99 22 56 81 31 65
 42 127 8 51 109 17 133 5 39 115 14 48 2 45 130 11 54 112 60 91 26 69 73 35 97 23 57 79 32 66 20 63 94 29 72 76
 134 6 37 116 15 46 3 43 131 12 52 113 40 128 9 49 110 18 98 24 55 80 33 64 21 61 95 30 70 77 58 92 27 67 74 36

 28 71 78 19 62 96 68 75 34 59 93 25 81 31 65 99 22 56 10 53 114 1 44 132 50 111 16 41 129 7 117 13 47 135 4 38
 69 73 35 60 91 26 79 32 66 97 23 57 29 72 76 20 63 94 51 109 17 42 127 8 115 14 48 133 5 39 11 54 112 2 45 130
 80 33 64 98 24 55 30 70 77 21 61 95 67 74 36 58 92 27 116 15 46 134 6 37 12 52 113 3 43 131 49 110 18 40 128 9

aijk (an order-6 pantriagonal magic cube)
 1 44 132 207 164 103 41 129 7 167 106 201 135 4 38 100 204 170 198 155 121 28 71 78 158 124 192 68 75 34 118 195 161 81 31 65
 42 127 8 166 108 200 133 5 39 102 203 169 2 45 130 206 163 105 157 126 191 69 73 35 120 194 160 79 32 66 197 154 123 29 72 76
 134 6 37 101 202 171 3 43 131 205 165 104 40 128 9 168 107 199 119 193 162 80 33 64 196 156 122 30 70 77 159 125 190 67 74 36

 189 146 139 19 62 96 149 142 183 59 93 25 136 186 152 99 22 56 10 53 114 216 173 85 50 111 16 176 88 210 117 13 47 82 213 179
 148 144 182 60 91 26 138 185 151 97 23 57 188 145 141 20 63 94 51 109 17 175 90 209 115 14 48 84 212 178 11 54 112 215 172 87
 137 184 153 98 24 55 187 147 140 21 61 95 150 143 181 58 92 27 116 15 46 83 211 180 12 52 113 214 174 86 49 110 18 177 89 208

Note By generalizing this method, we can construct a panmagic hypercube of any singly-even order and any odd dimension. (For even dimension, a panmagic hypercube of singly-even order cannot exist.) The order-6 pantriagonal magic cube by Gakuho Abe seems to have been constructed by a similar way to this method. Back

### 3.2 Associated pantriagonal magic cubes (m = 4x+2, m >= 6)

An associated pantriagonal magic cube aijk of order m, where i,j,k = 0,...,m-1, is given by the following equations:
aijk = bijk (m/2)3 + cijk + 1,

where
bijk = v1 (if t = (m-2)/4),
7-v0 (if t < (m-2)/4 and t + (m-2)/4 is even),
v0 (if t < (m-2)/4 and t + (m-2)/4 is odd),
cijk = k* (m/2)2 + i* (m/2) + j* (if i+j+k is even),
(m/2)3 - 1 - {k* (m/2)2 + i* (m/2) + j*} (if i+j+k is odd),
where
i* = i/2 (if i is even),
(m-1-i)/2 (if i is odd),
j* = j/2 (if j is even),
(m-1-j)/2 (if j is odd),
k* = k/2 (if k is even),
(m-1-k)/2 (if k is odd),
t = min[{(i* + j* - 2k*) mod (m/2)}, {(-i* - j* + 2k*) mod (m/2)}],
v0 = 4(k mod 2) + 2(j mod 2) + {(i+j+k) mod 2},
v1 = 7 - v0/2 (if v0 is even),
3 - (v0-1)/2 (if v0 is odd).

By generalizing this method, we can construct an associated panmagic hypercube of any singly-even order and any odd dimension.

Note (for m = 4x+2 and m >= 10)

If m is 10 or higher singly-even integer, we can construct another associated pantriagonal magic cube of order m. Such a magic cube aijk, where i,j,k = 0,...,m-1, is given by the following equations:
when m is not divisible by 3:
aijk = bijk (m/2)3 + cijk (m/2)2 + dijk (m/2) + eijk + 1,

when m is divisible by 3:
aijk = bijk (m/2)3 + Sm/2(cijk) (m/2)2 + Sm/2(dijk) (m/2) + Sm/2(eijk) + 1,

where
Sm/3(x) = Qm/6,3([x/3], x mod 3).

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).

The cubes bijk, cijk, dijk, and eijk are defined as follows:
bijk = G*8,m/2(v, z),
cijk = i + j + k + 1   (mod. m/2),   0 <= cijk < m/2,
dijk = i - j + k   (mod. m/2),   0 <= dijk < m/2,
eijk = i + j - k   (mod. m/2),   0 <= eijk < m/2,

where
v = 4[2i/m] + 2[2j/m] + {([2i/m] + [2j/m] +[2k/m]) mod 2},   (0 <= v <= 7),
z = i + j + k - 3(m-2)/4   (mod. m/2),   -(m-2)/4 <= z <= (m-2)/4.

The function G*N,m/2(v, z) (where N is a power of 2, m/2 is odd, and 0 <= v < N) is defined as follows:
when m/2 = 3 (mod. 4):
G*N,m/2(v, z) = v (if z = 0),
v/2 (if |z| > 0, z is even, and v is even),
N/2 + (v-1)/2 (if |z| > 0, z is even, and v is odd),
N - 1 - v/2 (if |z| > 0, z is odd, and v is even),
N/2 - 1 - (v-1)/2 (if |z| > 0, z is odd, and v is odd).

when m/2 = 1 (mod. 4):
G*N,m/2(v, z) = v (if z = 0),
N - 1 - v (if |z| = 1),
v/2 (if |z| > 1, z is even, and v is even),
N/2 + (v-1)/2 (if |z| > 1, z is even, and v is odd),
N - 1 - v/2 (if |z| > 1, z is odd, and v is even),
N/2 - 1 - (v-1)/2 (if |z| > 1, z is odd, and v is odd).

The function G*N,m/2(v, z) satifies the following properties (only these properties are needed for G*N,m/2(v, z)).

(1) { G*N,m/2(v, z) | 0 <= v < N } = { 0, 1, ..., N-1 } for every integer z,
(2) The sum Sumz=0,m/2-1{G*N,m/2(2v, z)} is independent of v,
(3) Sumz=0,m/2-1{G*N,m/2(2v, z)} + Sumz=0,m/2-1{G*N,m/2(2v+1, z)} = (N-1)m/2,
(4) G*N,m/2(v, z) = G*N,m/2(v, -z),
(5) G*N,m/2(v, z) + G*N,m/2(N-1-v, z) = N-1.

Here is an example for m = 10. 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. Magic Cubes and Tesseracts 