www.vector.org.uk >
back issues >
contents of Vector 16.3
During a recent exhibition, PROGILOG, held in Paris last November, the company Euriware gave me a funny advertising object: a little 3D puzzle.
|
The puzzle is made of six pieces, which are in fact the faces of a cube. The aim is to build the cube by embedding the pieces one into the other. Only 6 pieces: it looks very easy! In fact the multiple possibilities make the trick more complex than one might think. |
|
|
Each piece is a 5 by 5 square, the sides of which are notched as shown here. The piece thickness is equal to 1, which makes it possible to fit pieces. |
|
|
In APL, one can represent such an object by a binary matrix, like this: | 1 0 1 0 0 1 1 1 1 1 0 1 1 1 0 1 1 1 1 1 0 1 0 1 1 |
Of course one may rotate that piece by multiples of p/2, to obtain four configurations, which will be named “State 0” to “State 3”, depending on the number of p/2 rotations applied.
| State 0 | State 1 | State 2 | State 3 |
|---|---|---|---|
1 0 1 0 0 1 1 1 1 1 0 1 1 1 0 1 1 1 1 1 0 1 0 1 1 | 0 1 0 1 1 0 1 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1 0 1 0 | 1 1 0 1 0 1 1 1 1 1 0 1 1 1 0 1 1 1 1 1 0 0 1 0 1 | 0 1 0 1 1 1 1 1 1 0 0 1 1 1 1 1 1 1 1 0 1 1 0 1 0 |
But: it is strictly forbidden to turn the piece over.
You are given the 6 matrices which represent the six pieces, each given in its original position (State 0); here they are:
| Piece 1 | Piece 2 | Piece 3 |
|---|---|---|
1 0 1 0 0 1 1 1 1 1 0 1 1 1 0 1 1 1 1 1 0 1 0 1 1 | 0 0 1 0 1 0 1 1 1 1 1 1 1 1 0 0 1 1 1 1 0 1 0 1 1 | 0 1 0 1 0 1 1 1 1 0 0 1 1 1 1 1 1 1 1 0 1 1 0 1 1 |
| Piece 4 | Piece 5 | Piece 6 |
0 0 1 0 0 1 1 1 1 0 0 1 1 1 1 1 1 1 1 0 0 0 1 0 0 | 1 1 0 1 0 0 1 1 1 0 1 1 1 1 1 0 1 1 1 0 0 1 0 1 0 | 1 0 1 0 0 1 1 1 1 0 0 1 1 1 1 1 1 1 1 0 0 0 1 0 0 |
That set will be represented, in APL by a unique binary array, Bin, of dimensions 6×5×5. Because one could imagine many different shapes for the pieces, that binary array Bin will be our input data.
© Generate the example data (paste into your APL session!) Bin„6 5 5˝0 Bin[1;;]„5 5˝1 0 1 0 0,1 1 1 1 1,0 1 1 1 0,1 1 1 1 1,0 1 0 1 1 Bin[2;;]„5 5˝0 0 1 0 1,0 1 1 1 1,1 1 1 1 0,0 1 1 1 1,0 1 0 1 1 Bin[3;;]„5 5˝0 1 0 1 0,1 1 1 1 0,0 1 1 1 1,1 1 1 1 0,1 1 0 1 1 Bin[4;;]„5 5˝0 0 1 0 0,1 1 1 1 0,0 1 1 1 1,1 1 1 1 0,0 0 1 0 0 Bin[5;;]„5 5˝1 1 0 1 0,0 1 1 1 0,1 1 1 1 1,0 1 1 1 0,0 1 0 1 0 Bin[6;;]„5 5˝1 0 1 0 0,1 1 1 1 0,0 1 1 1 1,1 1 1 1 0,0 0 1 0 0
You just have to find out ALL the valid possible ways of building the cube (maybe there are more than one, who knows?)
But how can we represent each solution? Here again, we need conventions. We have decided on the following conventions:
|
With these conventions, any solution can be represented as shown here: (but, sorry: this is not a solution) |
|
| Each solution can simply be represented by a 6×2 APL matrix. The “solution” above would give: |
1 0 4 2 3 0 6 1 5 1 2 3 |
Your (monadic) program should take, as its right operand, the 6×5×5 binary matrix Bin, given above, and produce as its result an N×6×2 numeric array, where N is the number of solutions, each of which is represented as a 6×2 matrix, according to the conventions given in the previous section.
The problem can be extended if you are allowed to turn one or more pieces over, except the Base piece, which must remain unchanged (just to avoid symmetrical solutions).
To have the same representations for everybody, I suggest two additional conventions:
You can write a second program which will have an optional left operand, like this:
0 : pieces cannot be turned (the default)
1 : pieces can be turned upside down.
This new program will give a result of 3 columns:
Send your solutions (in any APL, J, K, 0, R, …) to Vector, of course, [email: apl385@compuserve.com. Postal address c/o Vector Production, Brook House, Gilling East, York YO62 4JJ, UK], but please also email them to the French APL Association secretary, Mrs Ludmila Lemagnen, at the following address: lemagnen@aol.com.
I hope you will have fun with the game!
Bernard Legrand, Legrand Consultants