NB. a cube will be a 3 4 $ of binary bits, representing the edges on the top, middle and bottom gencube =: {{ ? 3 4 $ 2 }} allcubes =: 3 4 $ "1 #: i. <:2^12 connectionMatrix =: 1 ((0 1) ; (0 3) ; (0 4) ; (0 5) ; (1 0) ; (1 2) ; (1 5) ; (1 6) ; (2 1) ; (2 3) ; (2 6) ; (2 7) ; (3 0) ; (3 2) ; (3 4) ; (3 7) ; (4 0) ; (4 3) ; (4 8) ; (4 11) ; (5 0) ; (5 1) ; (5 8) ; (5 9) ; (6 1) ; (6 2) ; (6 9) ; (6 10) ; (7 2) ; (7 3) ; (7 10) ; (7 11) ; (8 4) ; (8 5) ; (8 9) ; (8 11) ; (9 5) ; (9 6) ; (9 8) ; (9 10) ; (10 6) ; (10 7) ; (10 9) ; (10 11) ; (11 4) ; (11 7) ; (11 8) ; (11 10)) } 12 12 $ 0 connected =: 3 : 0 NB. all of the edges are connected cube =. ,/ y left =. I. cube connects =. {. left whilst. 0 < # connects do. try =. {. connects NB. remove traversed to node connects =. }. connects NB. find it's connections newconnections =. I. try { connectionMatrix NB. filter down to connections we can make validConnections =. (newconnections e. left) # newconnections NB. add those connections to connects connects =. ~. connects, validConnections NB. remove items from left, who are in connects left =. left -. connects end. 0 = # left ) three_d =: 3 : 0 NB. if the cube has at least 1 element in every direction dx =. (0 0);(0 2);(2 0);(2 2) dy =. (0 1);(0 3);(2 1);(2 3) dz =. (1 0);(1 1);(1 2);(1 3) tx =. +/ dx { y ty =. +/ dy { y tz =. +/ dz { y 0 < tx * ty * tz ) validCubes =: (2 = +/ |: (connected , three_d) "_1 allcubes) # allcubes pitch =: 3 : '3 4 $ (2 6 10 7 3 1 9 11 0 5 8 4) { ,/ y' roll =: 3 : '3 4 $ (4 3 7 11 8 0 2 10 5 1 6 9) { ,/ y' yaw =: 3 : '_1 |. "1 y' cartesian =: 3 : 0 , { (<@i. "0 y) ) rotate =: 4 : 0 cube =. x rotation =. >y p =. {. rotation r =. 1{rotation y =. 2{rotation yaw^:y roll^:r pitch^:p cube ) rotations =: 3 : 0 rots =. cartesian 4 4 4 y&rotate "0 rots ) keyrotation =: 3 : 0 rots =. ~. rotations y > {. (sort <"_1 rots) ) ioc =: ~. keyrotation "_1 validCubes iocSums =: +/ "1 +/ "_1 ioc edges =: (4 0 3 1 2 2 1 3 0 4) ; (0 4 0 5 0 6 0 7 0 8 0 9 0 10 0 11 0 12 0 13 0 14 0 15) ; (0 15 1 14 2 13 3 12 4 11) ; (4 0 4 1 4 2 4 3 4 4 4 5 4 6 4 7 4 8 4 9 4 10 4 11) ; (4 0 5 0 6 0 7 0 8 0 9 0 10 0 11 0 12 0) ; (0 4 1 4 2 4 3 4 4 4 5 4 6 4 7 4 8 4) ; (0 15 1 15 2 15 3 15 4 15 5 15 6 15 7 15 8 15) ; (4 11 5 11 6 11 7 11 8 11 9 11 10 11 11 11) ; (12 0 11 1 10 2 9 3 8 4) ; (8 4 8 5 8 6 8 7 8 8 8 9 8 10 8 11 8 12 8 13 8 14 8 15) ; (12 11 11 12 10 13 9 14 8 15) ; (12 0 12 1 12 2 12 3 12 4 12 5 12 6 12 7 12 8 12 9 12 10 12 11) pad =: 4 : ' x, (,&x "1 x&,"1 y), x' drawcube =: 3 : 0 ascii =: 13 16 $ ' ' lines =. (,y) # edges for_line. lines do. ascii =. '#' (_ 2 $ > line) } ascii end. ' ' pad ascii ) cubes =: < "_1 drawcube "_1 ioc cubegrid =: ,.|. iocSums ]/. cubes NB. set ascii output 9!:7 '+++++++++|-' (, ((": cubegrid),.LF)) 1!:2 <'cubes.txt'