Heronian triangles: Difference between revisions

Content deleted Content added
Tikkanz (talk | contribs)
→‎{{header|J}}: consistent case for noun/verb
Tikkanz (talk | contribs)
→‎{{header|J}}: alternative J implementation
Line 378:
perim=: +/"1 NB. perimeter
isPrimHero=: (0&~: * (= <.@:+))@A * 1 = a +. b +. c</lang>
 
'''Alternative Implementation'''
 
The implementation uses the symbols as given in the formulae at the top of the page, making it easier to follow along as well as spot any errors. The formulae distinguish between the individual sides of the triangles whereas J would normally treat these as a single entity or array. The implementation below uses that approach.
 
<lang J>perim=: +/"1
s=: -:@:perim
area=: [: %: s * [: */"1 s - ]
isNonZeroInt=: 0&~: *. (= <.@:+)
isPrimHero=: isNonZeroInt@area *. 1 = +./&.|:</lang>
 
'''Required tasks'''