Current issue

Vol.26 No.4

Vol.26 No.4

Volumes

© 1984-2024
British APL Association
All rights reserved.

Archive articles posted online on request: ask the archivist.

archive/16/3

Volume 16, No.3

This article might contain pre-Unicode character-mapped APL code.
See here for details.

Puzzle: Funny Cube

by Bernard Legrand

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.

[pic of cube]
That gave me the idea of a little problem that I am offering both to the members of the French APL association (AFAPL), and to the readers of Vector.

Representations

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.

[pic of piece]

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 0State 1State 2State 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.

Input Data

You are given the 6 matrices which represent the six pieces, each given in its original position (State 0); here they are:

Piece 1Piece 2Piece 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 4Piece 5Piece 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

The Game

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:

  1. Among the different representations of a cube, we have chosen the following one, where the faces have been named “A” to “F”:

    [pic of faces]

  2. It is also decided that the face “A”, in the leftmost position, will be occupied by the piece used as an example in the first paragraph, in its original state (piece number 1, in 0 state). It will be called “Base piece”.
  3. In order to represent each element of the solution, just give the piece number (1 to 6), followed by its rotation state (0 to 3).

With these conventions, any solution can be represented as shown here:

(but, sorry: this is not a solution)

PlacePieceState 
A 1 0 (Base piece)
B 4 2  
C 3 0  
D 6 1  
E 5 1  
F 2 3  

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 Program

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.

Extension

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:

  • the pieces will be turned over using a “reverse” along the last dimension: ²
  • the rotations will be made after a piece has been turned over.

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:

  • Piece number (1 to 6)
  • Has it been turned over (0 or1) ?
  • Number of p/2 rotations applied (0 to 3)

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
President of the French APL Association AFAPL

script began 5:36:14
caching off
debug mode off
cache time 3600 sec
indmtime not found in cache
cached index is fresh
recompiling index.xml
index compiled in 0.1797 secs
read index
read issues/index.xml
identified 26 volumes, 101 issues
array (
  'id' => '10004960',
)
regenerated static HTML
article source is 'HTML'
source file encoding is ''
read as 'Windows-1252'
URL: cube163.jpg => trad/v163/cube163.jpg
URL: cube01.gif => trad/v163/cube01.gif
URL: cube02.gif => trad/v163/cube02.gif
URL: http://www.apl-385.demon.co.uk/rcs/programs/java/java.htm => http://www.apl-385.demon.co.uk/rcs/programs/java/java.htm
URL: mailto:apl385@compuserve.com => mailto:apl385@compuserve.com
URL: mailto:lemagnen@aol.com => mailto:lemagnen@aol.com
completed in 0.21 secs