We can represent a Rubik's Cube as a net as follows (when solved):
WWW
WWW
WWW
GGGRRRBBBOOO
GGGRRRBBBOOO
GGGRRRBBBOOO
YYY
YYY
YYY
Each letter represents the corresponding colour (W
is white, G
green etc.)
It has been shown that there are exactly \$43,252,003,274,489,856,000\$ (~\$43\$ quintillion) different permutations that a Rubik's Cube can be in.
Your task is to take an integer between \$1\$ and \$43,252,003,274,489,856,000\$ and output the corresponding permutation, in the manner shown above. You may choose how the permutations are ordered, but the algorithm you use must be shown to generate a unique, and correct, permutation for each possible input.
Invalid permutation rules
Taken from this page
To start with, the centre of each 3x3 face must stay the same, as the centre square on a Rubik's Cube cannot be rotated. The entire cube can be rotated, changing where a face appears to be, but this doesn't affect the net of the cube.
If we say each permutation has a parity, based on the parity of the number of swaps to reach that permutation, we can say
Each corner piece has three possible orientations. It can be oriented correctly (0), clockwise (1) or counterclockwise (2). The sum of corner orientations always remain divisible by 3
Each legal rotation on the Rubik's Cube always flips an even number of edges so there can't be only one piece oriented wrong.
Considering the permutation of all the corners and edges, the overall parity must be even which means that each legal move always performs the equivalent of an even number of swaps (ignoring orientation)
For example the following three net are invalid outputs:
WWW
WWW
WWW
GGGWWWBBBOOO
GGGRRRBBBOOO
GGGRRRBBBOOO
YYY
YYY
YYY
(Too many whites/not enough reds)
WRW
WRW
WRW
GGGRWRBBBOOO
GGGWRRBBBOOO
YYGRWROOOBBB
YYY
GGY
YYY
(There are two red/green center squares and no white/yellow center squares.
In all valid permutations, the center squares are all different colours)
WWW
WWW
WWW
GGGRRRBBBOOO
GGGRRRBBBOOO
GGGRRRBBOYOO
YYY
YYY
YYB
(The yellow/orange/blue corner is rotated into an impossible permutation)
Rules
- You must prove, however way you wish, that the algorithm is valid. You do not have to enumerate every single permutation, as long as you prove the validity of your algorithm.
- As long as your program will work theoretically for all integers between \$1\$ and \$43,252,003,274,489,856,000\$, you don't have to worry about the practicalities of actually taking in inputs greater than your language can handle
- This means that, if your language/type/whatever can only handle numbers up to \$2^{53}-1\$, the program itself can fail if the input is greater than \$2^{53}-1\$, but the algorithm that you use should not.
- For example, if your Javascript program fails for an input of \$27,946,105,037,114,827,095\$ purely because that number is out of bounds, that's fine. However, if your algorithm were ported to a language with arbitrary sized integers and failed for that input, your program would not be valid.
- You must include some sort of proof of validity in your answer. This proof can prove the validity in any accepted proof method, except for enumerating all possibilities.
- You may choose to use an alternate input method if you wish, so long as:
- The input is bounded
- Each input corresponds to a unique output
- You clearly explain the input format and how it corresponds to each output
- You may change the characters used to use 6 different ASCII characters, between 33 (
!
) and 126 (~
), instead ofWGRBOY
- You may output in any manner you wish, so long as it forms a clear representation of a cube where all 6 faces are able to be shown, including any valid cube net, a single lined string or a 3D rendering. If you are unsure about a specific format, don't hesitate to ask in the comments.
This is a code-golf so the shortest code, in bytes, in each language wins.
Example valid outputs
YYY
YYY
YYY
GGGRRRBBBOOO
GGGRRRBBBOOO
GGGRRRBBBOOO
WWW
WWW
WWW
(The `W` and `Y` faces have been swapped)
ZZZ
+++
+}}
+[[}77ZZ7bbb
bb[}[[7}}+Z7
bb[}++[}}+Z7
7bb
[7Z
[7Z
(To start with, the colours have been mapped W -> +, G -> b, R -> [, B -> }, O -> Z and Y -> 7.
Then, the moves L, R, U and F' have been applied, in that order.
Notice that each centre square is different, and corresponds to the same colour as in the mapping)