When the same thing needs to be done to both the left and right arguments & and similar conjunctions can do the job.
isRightTriangle =: =/&([:+/*:) 3 4 isRightTriangle 5 1 On Mon, Mar 28, 2016 at 2:26 PM, 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
