17
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)
In the third invalid example it isn't just that the corner is in an invalid configuration, the r/y/o corner is an impossible corner due to r and o being opposite one another – fəˈnɛtɪk – 2019-09-07T14:54:13.200
Fixed the third invalid example (CC @fəˈnɛtɪk) – Jonathan Allan – 2019-09-07T15:05:19.237
The same problem was also in the second invalid example but i hadn't noticed it. It matters less there because the colours are messed up anyway – fəˈnɛtɪk – 2019-09-07T15:08:33.817
When you write that alternate input methods are allowed, does that mean that we can take input as a vector of positive integers $(a_1,a_2,a_3,a_4)$ with the constraint $a_1\leq 8!$, $a_2\leq3^7$, $a_3\leq 12!/2$, $a_4\leq 2^{11}$? (the product of those numbers is 43 quintillion) – Robin Ryder – 2019-09-07T20:02:41.410
Does outputting in any manner we wish include, for (e.g.) the solved cube, outputting the single line string
WWWWWWWWWGGGRRRBBBOOOGGGRRRBBBOOOGGGRRRBBBOOOYYYYYYYYY
? – Shaggy – 2019-09-07T21:08:21.2671@Shaggy Yes, a single line string is fine – caird coinheringaahing – 2019-09-07T21:52:56.293
It is a theorem that there is an bijection between the group of transformations and the legal states of the cubes. Therefore it would be sufficient to create a function which can decode a given string of transformations from a solved cube into a state, or even more easily, a string of faces since each transformation is a quarter clockwise turn on a given face, and so is distinguished by each face. Moreover, it is known that every state can be represented by a string of less than 27 transformations. So it is possible to generate all $6^{26}$ combinations, decode them, and then output them. – Juan Sebastian Lozano – 2019-09-08T04:12:48.377
I tried writing it, but I immediately ran into a wall with how to represent the cube. The best I could come up with is a graph with 8 points for each face (since the center stays put) where points which move together are connected. – Juan Sebastian Lozano – 2019-09-08T04:14:27.927
@cairdcoinheringaahing, edit that into the spec and you've got my
+1
. Currently it reads as though we're tied to the output format you've used, which, in my opinion, adds an unnecessary complication to an already challenging challenge. – Shaggy – 2019-09-08T12:23:05.777@Shaggy Edited in. I'd hoped that the final bullet point in the rules would have addressed the output format, but I've changed it to be (hopefully) less restrictive – caird coinheringaahing – 2019-09-08T12:28:27.137
@RobinRyder Yes, that's an acceptable input (It meets the requirements laid out in the post) – caird coinheringaahing – 2019-09-08T17:51:59.297