51
\$\begingroup\$

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.
\$\endgroup\$
6
  • 1
    \$\begingroup\$ Must we handle negative values or invalid edge triple? \$\endgroup\$
    – user202729
    Commented Oct 23, 2017 at 14:57
  • 2
    \$\begingroup\$ Very related. I'll leave it up to the rest of the community to decide if its a dup. \$\endgroup\$ Commented Oct 23, 2017 at 17:18
  • 2
    \$\begingroup\$ I think that using coordinates instead of lengths changes the challenge significantly \$\endgroup\$
    – Luis Mendo
    Commented Oct 23, 2017 at 18:24
  • 8
    \$\begingroup\$ There is no triangle with lengths 21, 38, 5, because 21 + 5 < 38. Is this an intentional pathological case that we have to handle? \$\endgroup\$
    – Kevin
    Commented Oct 23, 2017 at 22:31
  • 1
    \$\begingroup\$ @Kevin no you have not to handle this case. User202729 has already asked this question :) \$\endgroup\$
    – mdahmoune
    Commented Oct 24, 2017 at 6:44

85 Answers 85

3
\$\begingroup\$

Common Lisp, 64 bytes

(apply(lambda(x y z)(=(+(* x x)(* y y))(* z z)))(sort(read)#'<))

Try it online!

As usual in Common Lisp, true is T and false is NIL.

\$\endgroup\$
3
\$\begingroup\$

JavaScript 6, recursive way, 40 Bytes

f=(a,b,c)=>c<a|c<b?f(b,c,a):a*a+b*b==c*c

f=(a,b,c)=>c<a|c<b?f(b,c,a):a*a+b*b==c*c
console.log(f(4,5,3));
console.log(f(4,5,6));

C (gcc), 42 bytes

f(a,b,c){c=c<a|c<b?f(b,c,a):a*a+b*b==c*c;}

Try it online!

\$\endgroup\$
1
  • \$\begingroup\$ That's a nice approach! \$\endgroup\$
    – Arnauld
    Commented Dec 26, 2017 at 11:06
3
\$\begingroup\$

Perl 5, 34 +2 (-ap) bytes

$x+=($_*=$_)/2for@F;$_=grep/$x/,@F

seems that can be shortened to 29 +2 but there is a warning: smartmatch is experimental

$x+=($_*=$_)/2for@F;$_=$x~~@F

the question i couldn't prove but it works in all tests i've tried is if the number (a^2+b^2+c^2)/2 can be a substring of a number (a^2/2 b^2/2 or c^2/2) which would give a false positive.

Try It Online

\$\endgroup\$
4
  • \$\begingroup\$ This can cut down to 35 + 2 by eliminating the @F assignment: Try it online! \$\endgroup\$
    – Xcali
    Commented Feb 2, 2018 at 17:46
  • \$\begingroup\$ @Xcali, thanks, and even 34 +2, editing \$\endgroup\$ Commented Feb 3, 2018 at 7:45
  • \$\begingroup\$ We don't count -ap as +2 bytes, but, instead, Perl 5 with the -ap flags is not the same language as Perl 5 without any flags. \$\endgroup\$ Commented Jun 16, 2018 at 19:11
  • \$\begingroup\$ thanks Erik seems the rules have changed since i've posted, don't hesitate to update \$\endgroup\$ Commented Jun 17, 2018 at 18:36
3
\$\begingroup\$

Excel, 47 bytes

Returns FALSE for right-angled Triangles, else TRUE:

=ISERR(FIND(SQRT((A1^2+B1^2+C1^2)/2),A1&B1&C1))
\$\endgroup\$
2
  • 1
    \$\begingroup\$ Now that is clever \$\endgroup\$ Commented Jun 26, 2018 at 12:08
  • \$\begingroup\$ Is there proof why it work? \$\endgroup\$
    – l4m2
    Commented Jan 26, 2022 at 8:11
2
\$\begingroup\$

Proton, 31 bytes

k=>(sum(j*j for j:k)/2)**.5in k

Try it online!

Credit to user202729 for the idea go upvote them

\$\endgroup\$
2
\$\begingroup\$

Neim, 6 bytes

ᛦD𝐬ᚺS𝕚

Try it online!

\$\endgroup\$
2
  • \$\begingroup\$ Could you plz add some explanations? \$\endgroup\$
    – mdahmoune
    Commented Oct 25, 2017 at 15:54
  • \$\begingroup\$ @mdahmoune You can activate debug mode to see what's going on. \$\endgroup\$
    – Okx
    Commented Oct 25, 2017 at 15:56
2
\$\begingroup\$

Swift 3, 81 bytes

func r(v:[Int]){let a=v.sorted{$0<$1};print("\(a[0]*a[0]+a[1]*a[1]==a[2]*a[2])")}
\$\endgroup\$
2
\$\begingroup\$

Batch, 61 bytes

@cmd/cset/ax=%1*%1,y=%2*%2,z=%3*%3,!((x+y-z)*(y+z-x)*(z+x-y))

Outputs 1 or 0 appropriately.

\$\endgroup\$
2
\$\begingroup\$

Pyth, 14 bytes

K_m*ddSQqstKhK

Try it online!

\$\endgroup\$
0
2
\$\begingroup\$

Eukleides, 81 bytes

x=number("")^2;y=number("")^2;z=number("")^2
print x==y+z or y==x+z or z==y+x?1|0

I thought Eukleides would handle this nicely using geometric builtins, but this actually turned out to be longer than just testing against the Pythagorean theorem, because the right triangle assertion is picky about order, and we have to turn our sides into a triangle first:

d e f triangle number(""),number(""),number("")
print right(d,e,f)or right(e,f,d)or right(f,d,e)?1|0

...which is 100 bytes. One nice thing about that one is it'll error out given an impossible triangle. Anyway, for either one, input is via STDIN, output is 1 for right, 0 for non-right via STDOUT. Doing a function was actually longer in this instance.

\$\endgroup\$
0
2
\$\begingroup\$

C++, 156 bytes

bool f(int*a){int g=[](int*b){return b[0]>b[1]?b[0]>b[2]?0:2:b[1]>b[2]?1:2;}(a);int c[2]={g?0:1,g>1?1:2};return pow(a[c[0]],2)+pow(a[c[1]],2)==pow(a[g],2);}
\$\endgroup\$
3
  • 2
    \$\begingroup\$ Since this doesn't work without the #include<math.h>, you need to include it in the bytecount. Note that instead of using pow, you can just multiply each element with itself to avoid the #include. \$\endgroup\$
    – Steadybox
    Commented Oct 23, 2017 at 20:05
  • \$\begingroup\$ If possible, please include a link to an online testing environment so other people can try out your code! \$\endgroup\$
    – mdahmoune
    Commented Oct 23, 2017 at 20:53
  • \$\begingroup\$ 135 bytes \$\endgroup\$
    – ceilingcat
    Commented May 29, 2020 at 18:40
2
\$\begingroup\$

Racket, 109 bytes

#lang racket/base
(define (isright a b c)
  (if (equal? (+ (* a a) (* b b)) (* c c))
      "yes"
      "no"))

Try it online!

\$\endgroup\$
5
  • 2
    \$\begingroup\$ It seems not working for 5 3 4? \$\endgroup\$
    – mdahmoune
    Commented Oct 23, 2017 at 20:51
  • 2
    \$\begingroup\$ So this answer is not valid for the challenge. Also if you don't do trivial golfs such as those ones just because you're lazy then you are not a serious contender to the challenge. \$\endgroup\$
    – user202729
    Commented Oct 24, 2017 at 1:08
  • 1
    \$\begingroup\$ @user202729 While valid to point out, that may not be the most helpful way to address a new user. \$\endgroup\$ Commented Oct 24, 2017 at 17:18
  • \$\begingroup\$ @sdfbhg The "trivial golfs" being pointed out are that (1) by convention we say that a pure function (λ expression) is a valid solution, leaving the # lang and define to the header and (2) an easy way to make the code shorter is to delete spaces around parentheses. Also, you can return #t and #f rather than "yes" and "no", bringing us here. \$\endgroup\$ Commented Oct 24, 2017 at 17:18
  • \$\begingroup\$ The point of both of these is so that different Racket submissions can be on an equal footing: if one person decides to write #lang racket and leave in spaces while another does not, we can't easily compare the actually different optimizations they found. (Anyway, as has been also mentioned, your submission needs to be fixed to work for right triangles not listed in a-b-c order.) \$\endgroup\$ Commented Oct 24, 2017 at 17:20
2
\$\begingroup\$

Dyalog APL, 12 bytes

(+/2÷⍨×⍨)∊×⍨

Uses the same method as this Jelly answer.

Try it online!

\$\endgroup\$
0
2
\$\begingroup\$

Pyth, 11 10 bytes

}/sK^R2Q2K

Try it online!

My first Pyth submission! Explanation:

     R        right map
    ^ 2       squaring
       Q      of the input
   K          save this in K
  s           sum up
 /      2     divide by 2
}        K    test if this sum is in K

saved a byte thanks to Mr. Xcoder

\$\endgroup\$
1
  • \$\begingroup\$ 10 bytes: }/sK^R2Q2K or /K^R2Q/sK2 (the former returns True/False, the latter returns 1/0) \$\endgroup\$
    – Mr. Xcoder
    Commented Oct 23, 2017 at 19:35
2
\$\begingroup\$

APL (Dyalog), 10 bytes

(+/∊×∘2)×⍨

Try it online!

×⍨ square (lit. multiplication selfie)

() apply the following anonymous tacit function on that:

+/ the sum

 is a member of

×∘2 the doubled amounts

\$\endgroup\$
2
\$\begingroup\$

Two answers found by refining the answer by Steadybox and incorporating the technique in the Java answer by Kevin Cruijssen:

C, 52 bytes

f(a,b,c){return(a*=a)+(b*=b)==(c*=c)|b+c==a|c+a==b;}

C, 74 bytes

#define _(a,b,c)a*a+b*b==c*c||
f(a,b,c){return _(a,b,c)_(b,c,a)_(c,a,b)0;}

Test program

#include <stdio.h>
int test(int a, int b, int c, int expected)
{
    int actual = f(a,b,c);
    if (expected != actual) {
        fprintf(stderr, "%d %d %d => %d\n ", a,b,c, actual);
        return 1;
    }
    return 0;
}

int main()
{
    return test(5, 3, 4, 1)
        +  test(3, 5, 4, 1)
        +  test(12, 37, 35, 1)
        +  test(21, 38, 50, 0)
        +  test(210, 308, 250, 0)
        ;
}
\$\endgroup\$
2
  • \$\begingroup\$ If possible, please include a link to an online testing environment so other people can try out your code! \$\endgroup\$
    – mdahmoune
    Commented Oct 25, 2017 at 13:50
  • \$\begingroup\$ I've provided a main() - anyone can try the code! It's all standard C... \$\endgroup\$ Commented Oct 25, 2017 at 16:28
2
\$\begingroup\$

Swift 4, 68 bytes

func f(v:inout[Int]){v.sort();print(v[0]*v[0]+v[1]*v[1]==v[2]*v[2])}

Accepts a mutable array as inout argument and prints true or false.

Swift Sandbox.

\$\endgroup\$
2
\$\begingroup\$

Dyalog APL, 17 16 bytes

{(+/2÷⍨⍵*2)∊⍵*2}

Try it!

Outputs 1 for true, 0 for false.

Thanks to @Adám for 1 byte.

How it works

{(+/2÷⍨⍵*2)∊⍵*2}          # Anonymous function
 (     ⍵*2)               # Each input (⍵) to the 2nd power
    2÷⍨                   # divided by 2
  +/                      # Sum
           ∊              # "is in"
            ⍵*2           # Each input (⍵) to the 2nd power

This uses the same logic as @user202729's Jelly answer, so some credit goes to them.

\$\endgroup\$
2
  • \$\begingroup\$ You should probably update the code on the top, it still has those parens around ⍵*2 \$\endgroup\$
    – Adalynn
    Commented Oct 23, 2017 at 19:57
  • \$\begingroup\$ (⍵*2)÷2 can be golfed to 2÷⍨⍵*2. \$\endgroup\$
    – Adám
    Commented Oct 24, 2017 at 8:25
2
\$\begingroup\$

C# (53)

The shortest possible code I could find was the one that looks like the JAVA solution:

(a,b,c)=>{return(a*=a)+(b*=b)==(c*=c)|a+c==b|b+c==a;}

Try it online

Array-input (58)

a=>{Array.Sort(a);return a[0]*a[0]+a[1]*a[1]==a[2]*a[2];};
\$\endgroup\$
2
\$\begingroup\$

Add++, 25 18 bytes

D,f,?,caaBcB*#s/2=

Try it online!

-7 bytes thanks to mdahmoune

Yes, I got outgolfed in my own language by 7 bytes. So what?

How does it work?

D,f,?,      - Create a variadic function, f. Example arguments: [5 3 4]
      c     - Clear the stack;      STACK = []
      a     - Push the arguments;   STACK = [[5 3 4]]
      a     - Push the arguments;   STACK = [[5 3 4] [5 3 4]]
      Bc    - Push the columns;     STACK = [[5 5] [3 3] [4 4]]
      B*    - Product of each;      STACK = [25 9 16]
      #     - Sort the stack;       STACK = [9 16 25]
      s     - Push the sum;         STACK = [9 16 25 50]
      /     - Divide;               STACK = [9 16 2]
      2     - Push 2;               STACK = [9 16 2 2]
      =     - Equal;                STACK = [9 16 1]

Implicitly return the top element on the stack

Old version

D,f,?,c2 2 2B]a@BcB`#s/2=

The only difference is the squaring of each element (aaBcB* in the golfed version, 2 2 2B]a@BcB` in this version), so I'll quickly explain how this part works

              - Stack is currently empty
2 2 2         - Push 2 three times;             STACK = [2 2 2]
     B]       - Wrap the stack in an array;     STACK = [[2 2 2]]
       a      - Push the arguments as an array; STACK = [[2 2 2] [5 3 4]]
        @     - Reverse the stack;              STACK = [[5 3 4] [2 2 2]]
         Bc   - Push the columns of the stack;  STACK = [[5 2] [3 2] [4 2]]
           B` - Reduce each by exponentiation;  STACK = [25 9 16]
\$\endgroup\$
4
  • \$\begingroup\$ Why not push the input twice and reduce by multiplication? \$\endgroup\$
    – mdahmoune
    Commented Oct 24, 2017 at 22:20
  • \$\begingroup\$ @mdahmoune because I over complicate things. Golfing now \$\endgroup\$ Commented Oct 24, 2017 at 22:23
  • \$\begingroup\$ Upvote ;) please can you put the first solution too, it’s interesting \$\endgroup\$
    – mdahmoune
    Commented Oct 24, 2017 at 22:45
  • \$\begingroup\$ @mdahmoune added! \$\endgroup\$ Commented Oct 24, 2017 at 22:51
2
\$\begingroup\$

CJam, 12 11 bytes

This is depressingly long.

{$2f#)\:+=}

Try it online!

Anonymous block that takes input as an array of integers on the stack and returns 1 (truthy) or 0 (falsey).

Explanation:

{      e# Stack:        [12 37 35] 
 $     e# Sort:         [12 35 37]
 2f#   e# Square each:  [144 1225 1369]
 )     e# Pop:          [144 1225] 1369
 \     e# Swap:         1369 [144 1225]
 :+    e# Sum:          1369 1369
 =     e# Equal:        1
}      e# Result: 1 (truthy)

Old solution

{2f#_:+2/#)}

Try it online!

Anonymous block that takes an array of integers on the stack and returns a truthy or falsy integer.

\$\endgroup\$
7
  • \$\begingroup\$ I like the swap trick ;) \$\endgroup\$
    – mdahmoune
    Commented Oct 24, 2017 at 22:26
  • \$\begingroup\$ Is it possible to add a link to test the solution please? \$\endgroup\$
    – mdahmoune
    Commented Oct 24, 2017 at 22:28
  • \$\begingroup\$ @mdahmoune TIO links added, thanks. \$\endgroup\$ Commented Oct 25, 2017 at 2:33
  • \$\begingroup\$ @Challenger5 what are the rules for including code in the header/footer like that? If I accept the input as array (realize I can do now) and include "q~" in the header like you did my answer is only 8. \$\endgroup\$
    – kaine
    Commented Oct 30, 2017 at 17:46
  • \$\begingroup\$ @kaine The way CJam works is that {} defines an anonymous function that accepts input from the stack. q~ reads input and places it on the stack, and the ~ at the end runs the block. I don't have to score that part because anonymous functions are allowed by default, so I put it in the header/footer. \$\endgroup\$ Commented Oct 30, 2017 at 23:49
2
\$\begingroup\$

Stacked, 18 bytes

[sorted:*rev...+=]

Try it online!

Explanation

This is an anonymous function that takes an array of three integers. It sorts (sorted), squares each element of the array (:*), and reverses the array with rev. This will give an array with the largest value in the front. ... pushes each individual member of the array onto the stack, which would make the stack look like:

c^2  b^2  a^2

+ addes the top two members, yielding:

c^2  (b^2+a^2)

= tests for equality. yielding the expression a^2 + b^2 == c^2, which is only true for right triangles.

\$\endgroup\$
1
  • \$\begingroup\$ Like the :* part ;) \$\endgroup\$
    – mdahmoune
    Commented Oct 26, 2017 at 9:50
2
\$\begingroup\$

GNUOctave, 32 bytes

A=input("")
sum(A.^2)/2==max(A)^2

The input must be like : [1,2,3] so Octave can evaluate it to a Matrix.

A.^2 squares all the elements of the matrix.

Outputs 1 if the triangle is right-angled, 0 otherwise.

You can try it online : https://octave-online.net

Edit (27 bytes): I saw this answer I thought I could find a better solution. I took the idea of squaring the matrix at the beginning. I don't feel like this deserves upvotes since it wasn't really my whole idea to begin with.

A=input("").^2
sum(A)/max(A)

Outputs 2 if the triangle is right-angled and anything else if it isn't.

\$\endgroup\$
1
  • \$\begingroup\$ The newline counts as a byte too, better to replace it with ";", which also eliminates the spurious output (so the edited version is actually 28 bytes). The rules do require a specific output for both true and false cases; I don't think "anything else than 2" qualifies as specific. \$\endgroup\$
    – Bass
    Commented Oct 26, 2017 at 10:55
2
\$\begingroup\$

Jq 1.5, 31 23 bytes

map(.*.)|.[[add/2]]!=[]

Expects input in form of 3 element array, e.g. [5, 3, 4]

Expanded

  map(.*.)           # square each element
| .[[ add/2 ]]!=[]   # true if index of sum/2 element exists

Thanks to mdahmoune for suggesting shorter approach then my original one.

Try it online!


Jq 1.5, 31 bytes

sort|map(.*.)|(.[:2]|add)==.[2]

Expects input in form of 3 element array, e.g. [5, 3, 4]

Expanded

  sort                   # put elements in order
| map(.*.)               # square each element
| (.[:2]|add) == .[2]    # is sum of first two equal to third?

Try it online!

\$\endgroup\$
4
  • \$\begingroup\$ The problem is equivalent to whether (a² + b² + c²) ÷ 2 is in {a², b², c²}, do you think this approach will be shorter on Jq? \$\endgroup\$
    – mdahmoune
    Commented Oct 25, 2017 at 13:50
  • \$\begingroup\$ Indeed that's a better approach. Thanks! \$\endgroup\$
    – jq170727
    Commented Oct 25, 2017 at 15:35
  • \$\begingroup\$ Could you plz add also the first solution too :) \$\endgroup\$
    – mdahmoune
    Commented Oct 25, 2017 at 15:42
  • \$\begingroup\$ Done! See also original edit \$\endgroup\$
    – jq170727
    Commented Oct 25, 2017 at 15:55
2
\$\begingroup\$

Octave, 29 bytes

sum(a=input("").^2)==max(2*a)

Try it online!

Input has to be given in a format octave understands as a vector, like [3 5 4] or [12;35;37].

Checks for Pythagoras's theorem: first, square all the sides, then check if the sum of squares of all the sides is twice the square of the hypotenuse.

Output will be either ans = 1 or ans = 0

\$\endgroup\$
2
  • \$\begingroup\$ Could you add some explanations? \$\endgroup\$
    – mdahmoune
    Commented Oct 26, 2017 at 9:48
  • \$\begingroup\$ Sure. There you go. \$\endgroup\$
    – Bass
    Commented Oct 26, 2017 at 10:39
2
\$\begingroup\$

Go, 96 94 bytes

package r;import"sort";func I(i...int)bool{sort.Ints(i);return i[0]*i[0]+i[1]*i[1]==i[2]*i[2]}

Test:

import "r"
import "fmt"

func main() {
    fmt.Println(r.I(3, 5, 4))
    fmt.Println(r.I(12, 37, 35))
    fmt.Println(r.I(21, 38, 5))
    fmt.Println(r.I(210, 308, 15))
}

Try it online!

\$\endgroup\$
3
  • \$\begingroup\$ Is it possible to do it without sorting? \$\endgroup\$
    – mdahmoune
    Commented Oct 25, 2017 at 13:34
  • \$\begingroup\$ I tried to do some stuff with complex numbers, but they were all higher character count. import "math/cmplx";cmplx.Abs() \$\endgroup\$
    – Riking
    Commented Oct 26, 2017 at 5:17
  • \$\begingroup\$ You can drop the space between import and "sort" \$\endgroup\$
    – mdahmoune
    Commented Oct 26, 2017 at 7:10
2
\$\begingroup\$

Pushy, 10 8 bytes

GK2ek+=#

Try it online!

Managed to cut off two bytes by changing the approach, here's how it works now:

          \ Implicit Input                  eg. [3, 4, 5]
G         \ Sort the stack descendingly         [5, 4, 3]
 K2e      \ Square all items                    [25, 16, 9]
    k+    \ Sum last two                        [25, 25]
      =   \ Check equality (1 or 0)             [1]
       #  \ Output result                       PRINT: 1

Original Version, 10 bytes

gK2eSk2/=#

           \ Input implicitly on stack.              eg. [5, 4, 3]
 g         \ Sort the stack ascendingly.                 [3, 4, 5]
 K2e       \ Square all items.                           [9, 16, 25]
 Sk2/      \ Append stack sum divided by 2               [9, 16, 25, 25]
 =#        \ Print equality of last two items (1/0)      PRINT: 1
\$\endgroup\$
2
  • \$\begingroup\$ Could you plz add the first solution too? \$\endgroup\$
    – mdahmoune
    Commented Oct 26, 2017 at 9:28
  • \$\begingroup\$ @mdahmoune done. \$\endgroup\$
    – FlipTack
    Commented Oct 27, 2017 at 15:12
2
\$\begingroup\$

MY, 13 bytes

22ω^÷Σ2ω^=Σ𝔹←

Try it online!

This helped me realize ... I screwed up the NOT function (and the boolean conversion function).

How it works (cross-compatible function)

22ω^÷Σ2ω^=Σ𝔹←
2             = push 2 to the stack
 2ω^          = push ω^2 to the stack (functions vectorize)
    ÷         = pop a, then b. push a/b (rational) to the stack
     Σ        = sum
      2ω^=    = equality test with ω^2
          Σ𝔹  = boolean conversion
            ← = output
\$\endgroup\$
3
  • \$\begingroup\$ You can ask Dennis to pull it yourself here or by contacting him at [email protected] \$\endgroup\$ Commented Oct 24, 2017 at 10:44
  • \$\begingroup\$ Is it possible to avoid computing ω^2 twice? \$\endgroup\$
    – mdahmoune
    Commented Oct 25, 2017 at 13:33
  • \$\begingroup\$ Maybe somehow, but MY doesn't have a duplicate command yet. \$\endgroup\$
    – Adalynn
    Commented Oct 25, 2017 at 16:08
2
\$\begingroup\$

Axiom, 39 bytes

f x==(y:=sort x;y.1^2+y.2^2=y.3^2=>1;0)

f(x) function Input one list of at last 3 numbers

Output 1 (it is right triangle)

Output 0 (it is not right triangle)

\$\endgroup\$
2
\$\begingroup\$

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.