Introduction
In this TED-Ed video (which I'd recommend watching first), a puzzle is presented. 27 unit cubes must be painted with one of red, green, or purple on each face, so that they can be reassembled into a large 3x3x3 cube that shows only red on the outside, then a different arrangement that shows only green, and then only purple. One solution is presented at the end of the video, but it is not obviously generalisable (and there are lots more solutions).
Then, in this lazykh video, a simple algorithm for solving the puzzle is presented. It is as follows:
- Paint the faces that currently make up the exterior of the large cube green
- For each dimension of the cube (X, Y, Z), shift the arrangement of the cubes over in that direction by 1 unit
- Repeat these steps for each colour
The lazykh video has graphics which explain the algorithm more clearly than can be done in this textual medium, so I suggest you watch that as well.
This algorithm generalises easily for higher sizes and numbers of colours than 3 (e.g. a 5x5x5 cube which must be painted with 5 different colours). Interestingly, it also generalises to higher dimensions than 3, but I'll save that for a different challenge.
Challenge
Given the size \$ n \$ (where \$ n \$ is a positive integer) of the large cube, output a solution to the \$ n \times n \times n \$ version of this generalised puzzle.
Using the algorithm described above is certainly not the only way to find a solution, but I've included it as a starting-point. You are free to work out the solution however you choose.
Output should be given as a list of 6-tuples (or similar structure), representing the face colours of each small cube. The elements of the tuples should be from a predictable sequence of distinct values, (e.g. integers from \$ 0 \$ to \$ n - 1 \$), each representing a colour. The faces within a tuple can be in whatever order you choose but it must be consistent. The list should be flat and \$ n ^ 3 \$ in length, but its elements can be in any order (since they will need to be rearranged anyway for assembly into the \$ n \$ alien probes).
Test cases
Input Output
1 [(0, 0, 0, 0, 0, 0)]
2 [(0, 0, 0, 1, 1, 1), (1, 0, 0, 0, 1, 1), (0, 1, 0, 1, 0, 1), (1, 1, 0, 0, 0, 1), (0, 0, 1, 1, 1, 0), (1, 0, 1, 0, 1, 0), (0, 1, 1, 1, 0, 0), (1, 1, 1, 0, 0, 0)]
3 [(0, 0, 0, 2, 2, 2), (2, 0, 0, 1, 2, 2), (1, 0, 0, 0, 2, 2), (0, 2, 0, 2, 1, 2), (2, 2, 0, 1, 1, 2), (1, 2, 0, 0, 1, 2), (0, 1, 0, 2, 0, 2), (2, 1, 0, 1, 0, 2), (1, 1, 0, 0, 0, 2), (0, 0, 2, 2, 2, 1), (2, 0, 2, 1, 2, 1), (1, 0, 2, 0, 2, 1), (0, 2, 2, 2, 1, 1), (2, 2, 2, 1, 1, 1), (1, 2, 2, 0, 1, 1), (0, 1, 2, 2, 0, 1), (2, 1, 2, 1, 0, 1), (1, 1, 2, 0, 0, 1), (0, 0, 1, 2, 2, 0), (2, 0, 1, 1, 2, 0), (1, 0, 1, 0, 2, 0), (0, 2, 1, 2, 1, 0), (2, 2, 1, 1, 1, 0), (1, 2, 1, 0, 1, 0), (0, 1, 1, 2, 0, 0), (2, 1, 1, 1, 0, 0), (1, 1, 1, 0, 0, 0)]
6 https://gist.github.com/pxeger/a82bdce4427f487490ce0df19840807a#file-6-txt
20 https://gist.github.com/pxeger/a82bdce4427f487490ce0df19840807a#file-20-txt
Rules
- Your solution does not need to complete in reasonable time for large \$ n \$, but it must work in theory
- Standard loopholes are forbidden
- You may use any sensible I/O method
- This is code-golf, so the shortest code in bytes wins