Here's a nice puzzle: 
http://www.puzzle.dse.nl/teasers/index_us.html#cube_creatures

To solve this for hypercubes http://en.wikipedia.org/wiki/Hypercube a
(may be) interesting sub problem is how to construct the connection
matrix for higher dimensions.

First idea that came to my mind was (after some puzzling):

lohc=: 3 : 0
NB. np: number of points
NB. n: number of front & back planes (faces)
np=.4*n=.2*y2=.y-2

NB. vertice labels per pair of front-back faces
p=. i.n,4

NB. face selectors
s=. (,/_2(,.|.)\i.2*y2),.(n,y2-1)$,(,.>:)-."1 0~ 2*i.y2

NB. adjacent vertices
b=. ,/(|:@}.,.(_1&|.,.1&|.)@{.)"2 s{p

NB. connection matrix
c=.(,p) e."1  b

NB. rest of the program

)

The second idea is based on analyzing the pattern of the conn. matrix.
Starting with dimension 3, the c.m. can be constructed with the two sub
matrices M and I:

    0 1 0 1 1 0 0 0
    1 0 1 0 0 1 0 0
    0 1 0 1 0 0 1 0
M=  1 0 1 0 0 0 0 1
    1 0 0 0 0 1 0 1
    0 1 0 0 1 0 1 0
    0 0 1 0 0 1 0 1
    0 0 0 1 1 0 1 0

I=: =i.8

E.g. the cm for dimension 4:

       | M   I |
  cm = |       |
       | I   M |

Constructing the cm by (symbolic?) selection:

lohc1=: 3 : 0
  c=. ,./,./"."0 (=i.y-2) {'IM'

NB. rest of progr.
)

   (lohc-:lohc1)4
1

For 'larger' values the first idea is the faster one. But construction
time is almost negligible compared to the time taken by the rest of the
program (solving the puzzle).

Of course all this only holds if my interpretation of hypercubes and
adjacent vertices is correct. Anyway, the answer for dimension 3 (the
puzzle) is correct.

I'm interested in other possibilities for constructing the connection
matrix, and/or correcting my thinking about hypercubes in relation to
this connection matrix.  :-)


Thanks


=@@i


P.S.

Matrix M can be further divided in sub matrices M4 and I4:

       | M4  I4 |
  M  = |        |
       | I4  M4 |

   M4
0 1 0 1
1 0 1 0
0 1 0 1
1 0 1 0

   =i.4
1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1

Even further sub dividing is possible to solve the puzzle for
degenerated cubes (0-, 1- and 2-cubes: see ref. hypercubes), but these
are easily solved by hand. For solving the puzzle for dims 3 and higher
it's convenient using dim 8 sub matrices M and I.

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to