Mike Day wrote:
 
> This comes in a bit simpler:
>    pytrpla =: 3 : '/:~ |."1 >: 4$. $. (=/ >/~* +/~) *: }.i.>:y'
>
> The >/~ phrase ensures you only get decreasing triples.

Thanks for showing me this use of >/~* as a middle tine. It simplifies
things nicely.
 
Some months back Roger Hui posted 4 $. $. as a way to produce indexes,
and it stuck with me. Subsequent discussion shows that it has
performance limitations that other constructions don't, but for
demonstration projects like this I think it is optimal.
 
Within a few minutes of posting my original solution I realized that my
code included superfluous adjustments. I've noticed that the process of
cleaning up J code can be quite similar to what happens when I'm editing
English sentences for improvement of grammar and phrasing. It will be
good to get in the habit of giving several additional read-throughs,
even for programs that work.
 
I prefer Transpose on the brick over Reverse on the index-triples, both
for brevity and conceptual clarity.  The J convention of listing
high-order axis first means (z y x $ stuff), so |: implies the switch to
(x y z) ordering. At least, that's my impression.
 
The sort is unnecessary, so:
 
   pytrplb =: 13 : '>: 4$. $. |:(=/ >/~* +/~) *: }.i.>:y'
 
 
-- 
 
Tracy
 
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to