<"2 ] 3 kfaces C
|length error: kfaces
|   ,/(({.y)+"1({:y)*"1    (#^:_1"1#:@i.@(2^+/))"1 id),:"1({:y)*"1-.id

3-face of the cube should be included as well.


A simpler alternative:

kfcs=: 3 : 0
 t1=. t=. #:i.2^{:$y
 ;(<y) (*"1&{: ,:~"1 {...@] +"1 }:@[ *"1 {:@] )~&.> t1 <@([ ,~ ] #~ 0 =
+/@:*"1)"1 _ t
:
 t1=. (#~ x = +/"1 ) t=. #:i.2^{:$y
 y (*"1&{: ,:~"1 {...@] +"1 }:@[ *"1 {:@] )~"2 t1 ([ ,~ ] #~ 0 = +/@:*"1)"1 _
t
)

   <"2 ] 0 kfcs C
+-----+------+-----+------+-----+------+-----+------+
|4 3 0|4 3 _2|4 0 0|4 0 _2|0 3 0|0 3 _2|0 0 0|0 0 _2|
|0 0 0|0 0  0|0 0 0|0 0  0|0 0 0|0 0  0|0 0 0|0 0  0|
+-----+------+-----+------+-----+------+-----+------+

   <"2 ] 1 kfcs C
+------+-------+------+-------+
|4 3  0|4 0  0 |0 3  0|0 0  0 |
|0 0 _2|0 0 _2 |0 0 _2|0 0 _2 |
+------+-------+------+-------+
|4  3 0|4  3 _2|0  3 0|0  3 _2|
|0 _3 0|0 _3  0|0 _3 0|0 _3  0|
+------+-------+------+-------+
| 4 3 0| 4 3 _2| 4 0 0| 4 0 _2|
|_4 0 0|_4 0  0|_4 0 0|_4 0  0|
+------+-------+------+-------+

   <"2 ] 2 kfcs C
+-------+--------+
|4  3  0|0  3  0 |
|0 _3 _2|0 _3 _2 |
+-------+--------+
| 4 3  0| 4 0  0 |
|_4 0 _2|_4 0 _2 |
+-------+--------+
| 4  3 0| 4  3 _2|
|_4 _3 0|_4 _3  0|
+-------+--------+

   <"2 ] 3 kfcs C
+--------+
| 4  3  0|
|_4 _3 _2|
+--------+

faces are ordered to their diagonal vector.

Without left argument, all faces are given:

     $ kfcs C
27 2 3


For higher dimensions:

   2 (kfcs -:&(,@:(<"2)) kfaces) 4 3 0 _2,:_4 _3 _2 1
1

   $ kfcs 4 3 0 _2,:_4 _3 _2 1
81 2 4


R.E. Boss


> -----Oorspronkelijk bericht-----
> Van: [email protected] [mailto:programming-
> [email protected]] Namens Andrew Nikitin
> Verzonden: vrijdag 9 april 2010 22:01
> Aan: J programming
> Onderwerp: Re: [Jprogramming] boxes
> 
> 
> > From: Kip Murray
> >
> > Andrew, Oleg's dyadic verb faces below works correctly on my example
> > 4 3 0 ,: _4 _3 _2 -- try
> >
> > <"_1 [ 4 3 0 faces _4 _3 _2
> >
> > -- and Oleg claims his faces works in all dimensions, see his examples
> below.
> >
> 
> I Olegs verb returns (n-1) dimensional faces of n-dimensional boxes.
> I meant k dimensional faces of n-dimensional boxes.
> For regular cube 2-face is what normally called "face", 1-face is an edge
> and
> 0-face is a vertex.
> 
> require 'statfns'
> kfaces=:4 : 0"0 2
>   n=.{:$y
>   k=.x
>   id=.(i.n) (e."1) (n-k) comb n
>   ,/(({.y) +"1 ({:y) *"1 (#^:_1"1 #:@i.@(2 ^ +/))"1 id) ,:"1 ({:y) *"1 -
> .id
> )
> 
>    C=.4 3 0 ,: _4 _3 _2
>    <"2 ] 0 kfaces C
> ------T------T-----T------T-----T------T-----T------┐
> │4 3 0│4 3 _2│4 0 0│4 0 _2│0 3 0│0 3 _2│0 0 0│0 0 _2│
> │0 0 0│0 0  0│0 0 0│0 0  0│0 0 0│0 0  0│0 0 0│0 0  0│
> L-----+------+-----+------+-----+------+-----+-------
>    <"2 ] 1 kfaces C
> -------T------T------T------T------T-------T------T-------T------T-------T
> ------T-------┐
> │4 3  0│4 0  0│0 3  0│0 0  0│4  3 0│4  3 _2│0  3 0│0  3 _2│ 4 3 0│ 4 3 _2│
> 4 0 0│ 4 0 _2│
> │0 0 _2│0 0 _2│0 0 _2│0 0 _2│0 _3 0│0 _3  0│0 _3 0│0 _3  0│_4 0 0│_4 0
> 0│_4 0 0│_4 0  0│
> L------+------+------+------+------+-------+------+-------+------+-------+
> ------+--------
>    <"2 ] 2 kfaces C
> --------T-------T-------T-------T-------T--------┐
> │4  3  0│0  3  0│ 4 3  0│ 4 0  0│ 4  3 0│ 4  3 _2│
> │0 _3 _2│0 _3 _2│_4 0 _2│_4 0 _2│_4 _3 0│_4 _3  0│
> L-------+-------+-------+-------+-------+---------
> 
> _________________________________________________________________
> Hotmail has tools for the New Busy. Search, chat and e-mail from your
> inbox.
> http://www.windowslive.com/campaign/thenewbusy?ocid=PID28326::T:WLMTAGL:ON
> :WL:en-US:WM_HMP:042010_1
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm

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

Reply via email to