# Is my triangle right?

Given a, b, c the length of the three sides of a triangle, say if the triangle is right-angled (i.e. has one angle equal to 90 degrees) or not.

## Input

Three positive integer values in any order

## Output

Either a specific true output (true, 1, yes, ...) or a specific false output (false, 0, no, ...)

## Example

5, 3, 4        --> yes
3, 5, 4        --> yes
12, 37, 35     --> yes
21, 38, 50     --> no
210, 308, 250  --> no


## Rules

• The input and output can be given in any convenient format.
• In your submission, please state the true and the false values.
• No need to handle negative values or invalid edge triple
• Either a full program or a function are acceptable. If a function, you can return the output rather than printing it.
• If possible, please include a link to an online testing environment so other people can try out your code!
• Standard loopholes are forbidden.
• This is so all usual golfing rules apply, and the shortest code (in bytes) wins.
• Must we handle negative values or invalid edge triple? – user202729 Oct 23 '17 at 14:57
• Very related. I'll leave it up to the rest of the community to decide if its a dup. – Digital Trauma Oct 23 '17 at 17:18
• I think that using coordinates instead of lengths changes the challenge significantly – Luis Mendo Oct 23 '17 at 18:24
• There is no triangle with lengths 21, 38, 5, because 21 + 5 < 38. Is this an intentional pathological case that we have to handle? – Kevin Oct 23 '17 at 22:31
• @Kevin no you have not to handle this case. User202729 has already asked this question :) – mdahmoune Oct 24 '17 at 6:44

## CJam 10

q~$_.*~-+!  Simplest one I found but also shortest q reads input as string. Leave input formatted as array [3 4 5] ~ dumps it to stack$ sorts array
_ duplicates array
.* multiplies each element by itself
~ dumps array to stack
-+ determines largest minus two smallest numbers
! if 0 return 1 and 0 if anything else


Try it online

• If possible, please include a link to an online testing environment so other people can try out your code! – mdahmoune Oct 23 '17 at 20:53
• @mdahmoune sure. done. – kaine Oct 23 '17 at 20:57

proc R {a b c} {expr $a[set H ==hypot(]$b,$c)||$b$H$a,$c)||$c$H$a,$b)}  Try it online! Still too long. • You think it can be more golfed? – mdahmoune Oct 25 '17 at 12:42 • – sergiol Oct 26 '17 at 0:15 • – sergiol Oct 26 '17 at 0:20 • Thanx for the additional less golfed solutions, could you add them to the answer plz? – mdahmoune Oct 26 '17 at 9:46 • I already tried to understand some solutions posted on other answers, and it happens, I will add more golfy solutions to main answer using the same approach. I will not publish the fails on the main answer as they are more recent and less golfy; and are also clickable links on the comments to working online demos. – sergiol Oct 26 '17 at 17:19 # Pyt, 128 6 bytes ²ĐƩ₂⇹∈  Explanation:  implicit input (as a list, i.e., "[A,B,C]") ² square each element in the list Đ duplicate the list (on stack twice) Ʃ sum elements in list on top of stack ₂ divide sum by 2 ⇹ swap top two items on stack ∈ check if sum/2 is in the list of squares implicit print  Try it online! • If possible, please include a link to an online testing environment so other people can try out your code! – mdahmoune Feb 2 '18 at 11:02 • Back when I posted this answer, it wasn't on TIO – mudkip201 Feb 2 '18 at 13:13 # Mathematica 39 24 bytes With 15 bytes saved thanks to Jenny_mathy. #^2+#2^2==#3^2&@@Sort@#&  Sort ensures that the diagonal will be the third element of z. z[[1]]^2 means Example #^2+#2^2==#3^2&@@Sort@#&[{3,5,4}] (*True*)  • Can it be done as a function? – mdahmoune Oct 23 '17 at 15:39 • It is a pure function, employed as if it were a single word. – DavidC Oct 23 '17 at 20:12 • 3 bytes shorter #&@@(z=Sort@#)^2+z[[2]]^2==z[[3]]^2& – Keyu Gan Oct 23 '17 at 23:07 • 24 bytes: #^2+#2^2==#3^2&@@Sort@#& – J42161217 Oct 24 '17 at 16:50 # PHP, 48 47 bytes sort($a);echo($a[2]**2==$a[1]**2+$a[0]**2)?1:0;  Try it online! Outputs 1 for true, 0 for false. • If it is acceptable to emit empty string for false, you can shave the four character ternary. – Umbrella Jun 19 '18 at 21:34 # Excel VBA, 49 Bytes Anonymous VBE immediate window function that takes input from range [A1:C1] and output to the VBE immediate window. [2:2]=[(1:1)^2]:?[Or(A2+B2=C2,B2+C2=A2,A2+C2=B2)]  # Lua, 66 bytes function f(...)t={...}table.sort(t)print(t[1]^2+t[2]^2==t[3]^2)end  This could be simplified by using table call syntax which would mean that the table does not need to be constructed in the function, saving 9 bytes. Try it online! Try it online on tio.run! • PLZ could you add the two solutions? – mdahmoune Oct 26 '17 at 14:40 • Can be golfed with function f(...)t={...} – ATaco Oct 29 '17 at 22:24 • Are those not 66 bytes? – Jonathan Frech Oct 30 '17 at 0:41 # Pyth - 23 22 Bytes, 22 21 if falsy value doesn't need to be the same every time !-+^@KSQZ2^@K1 2^@K2 2  Try it online! Returns True or False or (if falsy value does not need to be the same every time) -+^@KSQZ2^@K1 2^@K2 2  Try it online! Returns 0 or a number other than 0 This can probably be golfed a lot Explanation: ! Logical negate; Makes 0 true and others false. Not necessary if falsy values can be different - Subtract + Add ^ To the power of @ Index in K Assign variable K, returning K S Sorted Q Input Z Zero 2 2 ^ To the power of @ Index in K Variable K 1 1 2 2 ^ To the power of @ Index In K Variable K 2 2 2 2  # 05AB1E, 5 bytes à‚nOË  Try it online! • some explanations plz :)? – mdahmoune Feb 2 '18 at 13:33 • nàsOQ is another. Not thinking it's possible below 5. – Magic Octopus Urn Feb 2 '18 at 15:23 # Julia 0.6, 14 bytes L->L'L∈2L.^2  Try it online! Based @mdahmoune's hint that "The problem is equivalent to whether (a² + b² + c²) ÷ 2 is in {a², b², c²}" - this expresses the condition "(a² + b² + c²) is in {2a², 2b², 2c²}" for a given array L=[a,b,c]. L'L is multiplying the array by itself as a matrix multiplication, so [a b c]*[a = a^2 + b^2 + c^2 b c]  L.^2 is elementwise squaring, so is equal to [a^2 b^2 c^2]. ∈ is a synonym to in, and checks membership - so the code checks that "sum of squares evaluates to twice of any one of the squares". Just saw @Dennis' previous Julia answer and saved a few bytes thanks to that. This golf improves on it by two bytes, by using L'L instead of L⋅L (⋅ is a 3-byte Unicode character). # PHP, 44 bytes echo($a**2+$b**2+$c**2)/2==max($a,$b,\$c)**2;


Try it online!

Half the sum of the squares of the sides should equal the square of the max side. Emits "1" for true and "" (empty string) for false.

The TIO link runs all the tests in a loop.

• Let me know if taking the inputs as three independently pre-set variables abuses the The input and output can be given in any convenient format. rule. – Umbrella Jun 19 '18 at 21:52

# JavaScript (Node.js), 45 bytes

(a,b,c)=>[a*=a,b*=b,c*=c].includes((a+b+c)/2)


Try it online!

Half the sum of the squares of the sides should equal the square of the max side. Returns a bool.

The TIO link runs all the tests in a loop.

• Making a shorthand function seemed shorter than a console.log(). – Umbrella Jun 19 '18 at 21:52

# APL NARS 14 chars

{⍵∊⍨√2÷⍨+/⍵*2}


(seen in some other answer) test:

  f←{⍵∊⍨√2÷⍨+/⍵*2}
f 3 4 5
1
f 1 1 1
0
f 5 3 4
1
f 3 5 4
1
f 12 37 35
1
f 21 38 50
0
f 210 308 250
0


Here ⍵ is the argument of function f.

{⍵∊⍨√2÷⍨+/⍵*2}
⍵*2} if ⍵=1 2 3, ⍵*2 will be 1 4 9 (square the argument ⍵)
+/     if ⍵*2 is 1 4 9 here sum it 1+4+9=14(sum list)
√2÷⍨       here makes d=sqrt( (sum list above)/2 )
⍵∊⍨            here return 1 if d is element of ⍵, else return 0
because ⍨ reverse arguments of its left operator ∊


This follow from this: Given a, b, c the length of one triangle, they are the length of one right triangle <=> a^2+b^2=c^2 and a,b,c different from 0.

  |\
| \
|  \
a|   \c
|    \
|_____\
b
a^2+b^2=c^2 <=> (a^2+b^2+c^2)/2=(2*a^2+2*b^2)/2=a^2+b^2=c^2 <=>
<=> (a^2+b^2+c^2)/2 ∊ {a^2, b^2, c^2}

• If possible, please include a link to an online testing environment so other people can try out your code! – mdahmoune Feb 2 '18 at 11:02
• @mdahmoune the code would run only in a Nars interpreter... I don't know where find that interpreter in the net...( Because I use one symbol function sqrt, not present in other Apl interpreters) So no trust in what I say... (for see if run ok one would have download Apl Nars, load the code , execute it) – RosLuP Feb 2 '18 at 11:41
• So could u plz explain your solution? – mdahmoune Feb 2 '18 at 11:56
• @mdahmoune done... I possibly make wrong something... – RosLuP Feb 2 '18 at 12:50
• @mdahmoune because I make one error in understand the code, so I change the explanation where I make that error (sqrt( sum/2)) – RosLuP Feb 2 '18 at 13:00

# SmileBASIC, 55 bytes

DEF R(T)SORT T
RETURN SQR(T[0]*T[0]+T[1]*T[1])==T[2]END

• If possible, please include a link to an online testing environment so other people can try out your code! – mdahmoune Oct 23 '17 at 20:54
• I don't think one exists, unfortunately. – 12Me21 Oct 23 '17 at 21:52
• Could you PLZ tell us how can test your code? – mdahmoune Oct 25 '17 at 12:46
• A quick search found this: en.m.wikipedia.org/wiki/Petit_Computer . I don't know if you can download it and run it on DSi emulator though. – Heimdall Nov 10 '17 at 8:52
• It appears it defines a function R with argument T and assumes T to be a zero indexed array containing 3 numbers. SQR must be square root function. Unlike other BASICs this one uses C-like == rather than = for comparison. I guess I would just have to find a copy of the manual online to assess it as the code is really straightforward. – Heimdall Nov 10 '17 at 9:04

# Lua, 90 bytes

t={...}for k,v in pairs(t)do t[k]=tonumber(v)end table.sort(t)print(t[1]^2+t[2]^2==t[3]^2)


Try it online!

# Japt, 7 bytes

øUx²z q


Try it online!