One option is to use a dyadic hook (rather than
5 (= +/)&:*: 3 4

If you want to use the same argument order as before:
3 4 (= +/)&:*:~ 5

Another option would be not to separate the triangle sides:
isRightTri=: ({: = +/@:}:)@:*:@/:~"1
   isRightTri 3 4 5 , 5 9 6 ,: 5 16 20
1 0 0


On Tue, Mar 29, 2016 at 9:26 AM, Adam Tornhill <[email protected]>
wrote:

> I'm moving on to learn J and try to get some practical exercise by working
> though problems from the Dyalog APL competition.
>
> One of the simpler problems is to write a verb that determines if the
> given legs of a triangle (left argument) and its hypotenuse (right
> argument) represent a right triangle. The solution was quick to code up:
>
> isRightTriangle =: (+/ @: *: @: [) = (*: @:])
>
> However, I'm left with a feeling that there must be a more elegant way. I
> set for a dyadic hook, but picking-out the left/right arguments like I do
> seems just wrong.
>
> I'd be happy for any tips and guidance on how one writes these kind of
> dyads in J.
>
> Thanks in advance!--
> Homepage: www.adamtornhill.com
> Twitter: @AdamTornhill
>
> Your Code as a Crime Scene:
> https://pragprog.com/book/atcrime/your-code-as-a-crime-scene
> Lisp for the Web:  https://leanpub.com/lispweb
> Patterns in C: https://leanpub.com/patternsinc
> ----------------------------------------------------------------------
> 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