# Magic Cubes of prime orders

### Sep. 25, 1996

Recently I find a deductive algorithm to construct a perfect magic cubes such that the each order N is prime number greater than 6.

• ## What is perfect magic cube?

Perfect magic cube is more super than ordinary magic cube. It has the following feature:
• The sum for each rows, columns, poles or pan-diagonals is the same value.
• Pan-diagonal is a kind of cyclic diagonal defined by congruence.
```
*oooo     o*ooo  oo*oo
o*ooo     oo*oo  ooo*o
oo*oo     ooo*o  oooo*  ...
ooo*o     oooo*  *oooo
oooo*     *oooo  o*ooo

diagonal   pan-diagonals

```
• ## Algorithm

1. Move the location by a knight jump, thus the unit vector of the movement is (1,2,0), if it's possible.
2. If you fail the first movement, move the location by the rule in which the unit vector of the movement is (1,2,2).
3. If you fail the first movement and the second movement above, move it by the unit vector (1,0,0).

• ## Implementation

I have implemented the above algorithm by a gnu-awk script:

```          gawk -f primecube.awk
```

Then, type the order. For example, if you type 7, the script outputs 7x7x7 magic cube. The number must be prime number. The number must be larger than 6.

• ## Limitation of the algorithm

The algorithm is only available for a prime number as the order of cube N. And N must be greater than 6.

• ## What to do.

• Without writing here, we need a general algorithm to construct a half-even (thus 4m+2 type) order magic cube.
• The algorithm can provide a particular cube, but exhaustive algorithm is still unknown. We need it.
• We have a function T2(N) which gives the total number of perfect magic squares. But We do not know T3(N), or Tm(N) of m-dimensional hyper space.

• ## Note.

• This script can produce only prime order perfect magic cubes. And the order must be larger than 6. However, it is known that there exists 4x4x4, 5x5x5, 6x6x6 order of perfect magic cube. Only a 3x3x3 magic cube is not perfect. If you need, I can upload the data here. The data written in a Japanese book were calculated by some Japanese manias, not mine.
• There exist some ad hoc algorithms for non-prime order magic cubes. For example, if we choose (2,2,0) as the first unit movement, and (0,2,2) as the second unit movement in my algorithm, we can obtain a 5x5x5 perfect magic square.
• We do not know how we choose the unit movements systematically.
• The famous algorithm for full-even (4m) type magic cubes is known. It is not known who found it. I will introduce the algorithm someday.

• ## An Example

The following magic cube (11x11x11) is calculated by the awk script.

N=11
Equi-sum=7326
 1 1199 934 669 404 139 1326 1061 796 531 266 871 606 473 208 1274 1009 744 600 335 70 1136 410 145 1211 1078 813 548 283 18 1205 940 675 1280 1015 750 485 352 87 1153 888 623 479 214 819 554 289 24 1090 957 692 427 162 1228 1084 358 93 1159 894 629 364 231 1297 1032 767 502 1107 963 698 433 168 1234 969 836 571 306 41 646 381 237 1303 1038 773 508 243 110 1176 911 185 1251 986 842 577 312 47 1113 848 715 450 1055 790 525 260 116 1182 917 652 387 122 1320 594 329 64 1130 865 721 456 191 1257 992 727
 134 1321 1067 802 537 272 7 1194 929 664 399 1004 739 595 341 76 1142 877 612 468 203 1269 543 278 13 1200 946 681 416 151 1217 1073 808 82 1148 883 618 474 220 1286 1021 756 491 347 952 687 422 157 1223 1079 825 560 295 30 1096 370 226 1292 1027 762 497 353 99 1165 900 635 1240 975 831 566 301 36 1102 958 704 439 174 779 514 249 105 1171 906 641 376 232 1309 1044 318 53 1119 854 710 445 180 1246 981 837 583 1188 923 658 393 128 1315 1050 785 520 255 111 716 462 197 1263 998 733 589 324 59 1125 860
 267 2 1189 935 670 405 140 1327 1062 797 532 1137 872 607 463 209 1275 1010 745 601 336 71 676 411 146 1212 1068 814 549 284 19 1206 941 215 1281 1016 751 486 342 88 1154 889 624 480 1085 820 555 290 25 1091 947 693 428 163 1229 503 359 94 1160 895 630 365 221 1298 1033 768 42 1108 964 699 434 169 1235 970 826 572 307 912 647 382 238 1304 1039 774 509 244 100 1177 451 186 1252 987 843 578 313 48 1114 849 705 1310 1056 791 526 261 117 1183 918 653 388 123 728 584 330 65 1131 866 722 457 192 1258 993
 400 135 1322 1057 803 538 273 8 1195 930 665 1270 1005 740 596 331 77 1143 878 613 469 204 809 544 279 14 1201 936 682 417 152 1218 1074 348 83 1149 884 619 475 210 1287 1022 757 492 1097 953 688 423 158 1224 1080 815 561 296 31 636 371 227 1293 1028 763 498 354 89 1166 901 175 1241 976 832 567 302 37 1103 959 694 440 1045 780 515 250 106 1172 907 642 377 233 1299 573 319 54 1120 855 711 446 181 1247 982 838 112 1178 924 659 394 129 1316 1051 786 521 256 861 717 452 198 1264 999 734 590 325 60 1126
 533 268 3 1190 925 671 406 141 1328 1063 798 72 1138 873 608 464 199 1276 1011 746 602 337 942 677 412 147 1213 1069 804 550 285 20 1207 481 216 1282 1017 752 487 343 78 1155 890 625 1230 1086 821 556 291 26 1092 948 683 429 164 769 504 360 95 1161 896 631 366 222 1288 1034 308 43 1109 965 700 435 170 1236 971 827 562 1167 913 648 383 239 1305 1040 775 510 245 101 706 441 187 1253 988 844 579 314 49 1115 850 124 1311 1046 792 527 262 118 1184 919 654 389 994 729 585 320 66 1132 867 723 458 193 1259
 666 401 136 1323 1058 793 539 274 9 1196 931 205 1271 1006 741 597 332 67 1144 879 614 470 1075 810 545 280 15 1202 937 672 418 153 1219 493 349 84 1150 885 620 476 211 1277 1023 758 32 1098 954 689 424 159 1225 1081 816 551 297 902 637 372 228 1294 1029 764 499 355 90 1156 430 176 1242 977 833 568 303 38 1104 960 695 1300 1035 781 516 251 107 1173 908 643 378 234 839 574 309 55 1121 856 712 447 182 1248 983 257 113 1179 914 660 395 130 1317 1052 787 522 1127 862 718 453 188 1265 1000 735 591 326 61
 799 534 269 4 1191 926 661 407 142 1329 1064 338 73 1139 874 609 465 200 1266 1012 747 603 1208 943 678 413 148 1214 1070 805 540 286 21 626 482 217 1283 1018 753 488 344 79 1145 891 165 1231 1087 822 557 292 27 1093 949 684 419 1024 770 505 361 96 1162 897 632 367 223 1289 563 298 44 1110 966 701 436 171 1237 972 828 102 1168 903 649 384 240 1306 1041 776 511 246 851 707 442 177 1254 989 845 580 315 50 1116 390 125 1312 1047 782 528 263 119 1185 920 655 1260 995 730 586 321 56 1133 868 724 459 194
 932 667 402 137 1324 1059 794 529 275 10 1197 471 206 1272 1007 742 598 333 68 1134 880 615 1220 1076 811 546 281 16 1203 938 673 408 154 759 494 350 85 1151 886 621 477 212 1278 1013 287 33 1099 955 690 425 160 1226 1082 817 552 1157 892 638 373 229 1295 1030 765 500 356 91 696 431 166 1243 978 834 569 304 39 1105 961 235 1301 1036 771 517 252 108 1174 909 644 379 984 840 575 310 45 1122 857 713 448 183 1249 523 258 114 1180 915 650 396 131 1318 1053 788 62 1128 863 719 454 189 1255 1001 736 592 327
 1065 800 535 270 5 1192 927 662 397 143 1330 604 339 74 1140 875 610 466 201 1267 1002 748 22 1209 944 679 414 149 1215 1071 806 541 276 881 627 483 218 1284 1019 754 489 345 80 1146 420 155 1232 1088 823 558 293 28 1094 950 685 1290 1025 760 506 362 97 1163 898 633 368 224 829 564 299 34 1111 967 702 437 172 1238 973 247 103 1169 904 639 385 241 1307 1042 777 512 1117 852 708 443 178 1244 990 846 581 316 51 656 391 126 1313 1048 783 518 264 120 1186 921 195 1261 996 731 587 322 57 1123 869 725 460
 1198 933 668 403 138 1325 1060 795 530 265 11 616 472 207 1273 1008 743 599 334 69 1135 870 144 1221 1077 812 547 282 17 1204 939 674 409 1014 749 495 351 86 1152 887 622 478 213 1279 553 288 23 1100 956 691 426 161 1227 1083 818 92 1158 893 628 374 230 1296 1031 766 501 357 962 697 432 167 1233 979 835 570 305 40 1106 380 236 1302 1037 772 507 253 109 1175 910 645 1250 985 841 576 311 46 1112 858 714 449 184 789 524 259 115 1181 916 651 386 132 1319 1054 328 63 1129 864 720 455 190 1256 991 737 593
 1331 1066 801 536 271 6 1193 928 663 398 133 738 605 340 75 1141 876 611 467 202 1268 1003 277 12 1210 945 680 415 150 1216 1072 807 542 1147 882 617 484 219 1285 1020 755 490 346 81 686 421 156 1222 1089 824 559 294 29 1095 951 225 1291 1026 761 496 363 98 1164 899 634 369 974 830 565 300 35 1101 968 703 438 173 1239 513 248 104 1170 905 640 375 242 1308 1043 778 52 1118 853 709 444 179 1245 980 847 582 317 922 657 392 127 1314 1049 784 519 254 121 1187 461 196 1262 997 732 588 323 58 1124 859 726