# Calculating the Permutations of 4D Magic Cubes

by Eric Balandraud

This paper details the process of coounting the exact number of unique positions that 4D magic cubes of varying edge lengths are reachable from their pristine positions.

There are four types of hyper-cubies: those with 1, 2, 3, or 4 hyper-stickers. We'll refer them here as 1-colored, 2-colored, etc.

## 3x3x3x3

For the 3x3x3x3, we can count
• 16 4-colored,
• 32 3-colored, and
• 24 2-colored
• The 8 1-colored elements are immobile and will allow us to locate the position of every other element.

There are two steps to this process. The first one consists of counting the possible positions the cube can be constructed with regardless of positions that are unreachable from the pristine cube. The second step factors out the unreachable positions. Not all the permutations of the 24 2-colored and the 32 3-colored are possible. Only the permutations that have the same parity on the 2-colored and the 3-colored. To check that, it is enough to consider the basic moves of one face. So the number of positions reachable by just the 2-colored pieces is
(24!x32!)/2
All the even permutations of the 4-colored, and the odd ones are impossible, It can be checked on the basic moves, so we count
16!/2
The second step, now that the maximum number of positions are determined, notice that the 2-colored pieces can have two positions on one place, but the position of the last one is fully determined by the positions of the 23 others, giving
2^23
Every 3-colored can have 3! positions on one place, except for the last one, which can only have 3 positions, giving
(3!)^31 x 3
Finally, the 4-colored, can have 4!/2 positions on one place, except for the last one, which can have only 4 position giving
(4!/2)^15 x 4
All these counts, are independant of each other so the positions of the 3x3x3x3 is the product of all thiese numbers. Therefore the number of reachable positions for the 3x3x3x3 is exactly
(24!x32!)/2 x 16!/2 x 2^23 x (3!)^31 x 3 x (4!/2)^15 x 4
whose decimal expansion is
1 756 772 880 709 135 843 168 526
079 081 025 059 614 484 630 149
557 651 477 156 021 733 236 798
970 168 550 600 274 887 650 082
354 207 129 600 000 000 000 000
or aproximately 10^120.

## 4x4x4x4

The 4x4x4x4 has:
• 16 4-colored,
• 64 3-colored,
• 96 2-colored, and
• 64 1-colored
• One additional subtility with the 4x4x4x4 is that there aren't any pieces at the 2D face centers from which to orient our calculations. we therefore need to fix an element to locate all the others, let's fix a 4-colored (it can also be done with a 3-colored).

The even permutations of the 4 colored are possible, so
(15!/2)
And they can have 4!/2 positions but the last, only 4, so
((4!/2)^14)*4
Note that we have fix one of them, so it differs from the counts of the 3x3x3x3.

This time, all the permutations are even for the 3-colored, so
64!/2
(Note that on the 4x4x4, the 2-colored accepts odd permitations)

The 3-colored have 3 positions, on a place, and the last is fully determined by the 63 preceeding, so
3^63
Note that this differs from the 3x3x3x3, and that two 3-colored that have identical colors can't be in the same position and orientation.

The 2-colored accept only even permutations, but as they come in indistinguisable pairs, we count only the visually
different positions, giving
(96!/2)/((4!)^24/2)  =  96!/((4!)^24)
or 2^95, because the position of the last is determined by the others.

The same problem appears for the visually different positions of the 1-colored, so
(64!/2)/((8!)^8/2)
giving a grand total of
(15!/2)*((4!/2)^14)*4*(64!/2)*(3^63)*(96!/2)/((4!)^24/2)*(2^95)*(64!/2)/((8!)^8/2)
whose decimal expansion is
130 465 639 524 605 309 368 634 620 044
528 122 859 025 488 438 611 959 323 482 221 544 701 493 566
589 669 139 598 204 956 926 940 147 059 366 252 849 247 482
898 636 104 705 417 194 760 866 897 307 590 845 202 461 293
100 468 293 214 262 958 591 194 739 437 727 430 945 469 384
490 361 714 647 847 550 801 897 750 293 894 453 665 815 572
829 257 758 907 425 128 919 808 862 616 259 604 997 210 112
000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
or aproximately 10^334

You can verify this by fixing one of the 3-colored at the beginnig yielding a different formula, but the same result.

## 5x5x5x5

The 5x5x5x5 has there different families of 1-colored, 2-colored and 3-colored:
• 1-colored:
• 1 group of 48
1 group of 96
1 group of 64
• 2-colored:
• 1 group of 24
1 group of 96
1 group of 96
• 3-colored:
• 1 group of 32
1 group of 64
• 4-colored:
• 1 group of 16
for a grand total of
(16!/2) * (24!*32!/2) * 64!/2 * (96!/24^24)^2 * 64!/(8!)^8 * 96!/(12!)^8 * 48!/(6!)^8 * 12^16/3 * 6^32/2 * 3^64/3 * 2^24/2 * (2^96/2)^2
whose decimal expansion is
123 657 056 923 899 002 698 227 805 778 387 808 933 769
666 084 597 331 170 345 244 675 638 825 481 620 700 008 237 306 084 142 730 598
637 705 860 008 300 844 182 287 747 674 018 136 874 315 751 080 178 664 887 107
264 876 848 935 590 538 625 767 958 284 656 419 396 560 246 923 935 065 962 447
405 384 165 866 873 326 263 467 921 778 683 862 961 389 770 831 926 039 889 601
733 193 275 112 578 283 448 018 613 526 925 847 925 558 456 540 351 327 099 176
534 335 451 141 045 209 002 537 535 755 031 468 961 150 691 008 214 712 492 137
716 092 251 416 854 303 972 448 469 954 444 917 129 644 451 683 375 275 906 483
623 456 408 625 743 663 232 956 462 751 569 098 735 992 247 230 927 473 597 130
714 467 427 915 529 825 001 467 413 803 400 014 037 257 220 682 520 596 555 932
663 885 324 005 539 599 667 276 944 926 310 400 000 000 000 000 000 000 000 000
000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
Over 10^700. Quite a number!