Is this a triangle?

36

3

Task

Write a function/program that, given three positive integers a, b and c, prints a Truthy value if a triangle (any triangle) could have side lengths a, b and c and outputs a Falsy value otherwise.

Input

Three positive integers in any sensible format, for example:

  • three distinct function arguments, f(2, 3, 5)
  • a list of three numbers, [2,3,5]
  • a comma-separated string, "2,3,5"

You may not assume the inputs are sorted.

Output

A Truthy value if a triangle could have the sides with the lengths given, Falsy otherwise.

Test cases

1, 1, 1 -> Truthy
1, 2, 3 -> Falsy
2, 1, 3 -> Falsy
1, 3, 2 -> Falsy
3, 2, 1 -> Falsy
3, 1, 2 -> Falsy
2, 2, 2 -> Truthy
3, 4, 5 -> Truthy
3, 5, 4 -> Truthy
5, 3, 4 -> Truthy
5, 4, 3 -> Truthy
10, 9, 3 -> Truthy
100, 10, 10 -> Falsy

This is so shortest solution in bytes, wins. Consider upvoting this challenge if you have fun solving it and... Happy golfing!

RGS

Posted 2020-02-12T07:08:48.943

Reputation: 5 047

3Related: count the number of triangles – Kevin Cruijssen – 2020-02-12T07:29:44.047

6You ask: "is this a triangle?" Probably not, but who knows. Is anything really a triangle? – Lyxal – 2020-02-12T09:47:12.710

2@Lyxal I say you can be anything. I believe in you. Do you? – RGS – 2020-02-12T13:14:10.390

8△ △ ▽ ▽ ◁ ▷ ◁ ▷ A B ␂ – S.S. Anne – 2020-02-12T15:19:14.507

1you should at least admit that your test-cases 1,2,3 are "borderline triangles" as the shorter sides summed give the longest side so you have a "triangle on a line" - while 100,10,10 definitely is false as 10+10 is shorter than 100 – eagle275 – 2020-02-13T07:33:23.747

1@eagle275 while I understand what you mean, I do not wish to allow degenerate triangles into the Truthy test cases! If it doesn't have three distinct sides, it is not a triangle! – RGS – 2020-02-13T07:41:40.697

@RGS, the problem with 1, 2, 3 isn't that it doesn't have 3 distinct sides (they are mutually distinct both as lengths and as line segments), but rather that 2 of the sides are contained in the other one.

– LSpice – 2020-02-13T15:46:34.413

1@LSpice thanks for your message :) I thought I was using rigorous language when I called a "degenerate triangle" to a triangle in the conditions you just described. Was I inaccurate? Because what you said was what I meant. – RGS – 2020-02-13T15:48:27.743

@RGS, yes, degenerate triangle is the usual phrase for that, and I didn't mean to object to it, only to the 'distinct sides' language.

– LSpice – 2020-02-13T16:22:37.587

Answers

31

Python, 24 bytes

lambda l:sum(l)>max(l)*2

Try it online!

Checks if a+b+c > max(a,b,c)*2. If, say, c is the biggest one, this is equivalent to a+b+c>2*c, or a+b>c, which is want we want for the triangle inequality.

xnor

Posted 2020-02-12T07:08:48.943

Reputation: 115 687

3This is also what I had for Python! +1 for us :p – RGS – 2020-02-12T07:22:59.583

26

CP-1610 machine code (Intellivision), 12 DECLEs1 = 15 bytes

A routine taking \$(a,b,c)\$ into R0, R1 and R2 respectively and setting the carry if \$(a,b,c)\$ is not a triangle, or clearing it otherwise.

083     |         MOVR    R0,     R3
0CB     |         ADDR    R1,     R3
15A     |         CMPR    R3,     R2
02F     |         ADCR    R7
0D3     |         ADDR    R2,     R3
049     |         SLL     R1
159     |         CMPR    R3,     R1
201 002 |         BC      @@rtn
048     |         SLL     R0
158     |         CMPR    R3,     R0
0AF     | @@rtn   JR      R5

How?

Instead of testing:

$$\cases{a+b>c\\a+c>b\\b+c>a}$$

We test:

$$\cases{a+b>c\\a+b+c>2b\\a+b+c>2a}$$

The left parts of the inequalities are stored into R3. If the first test fails (when \$a+b\$ is stored into R3 and compared with R2), the carry is set and added to the program counter (R7), forcing the next instruction to be skipped. Consequently, R3 is not updated to \$a+b+c\$ and the last 2 comparisons are turned into:

$$\cases{a+b>2b\\a+b>2a}\Leftrightarrow\cases{a>b\\b>a}$$

which of course is never true, so the test is guaranteed to fail as expected.

All in all, this saves a branch which would have cost 1 extra DECLE.

Full commented test code

        ROMW    10                ; use 10-bit ROM width
        ORG     $4800             ; map this program at $4800

        ;; ------------------------------------------------------------- ;;
        ;;  main code                                                    ;;
        ;; ------------------------------------------------------------- ;;
main    PROC

        SDBD                      ; set up an interrupt service routine
        MVII    #isr,   R0        ; to do some minimal STIC initialization
        MVO     R0,     $100
        SWAP    R0
        MVO     R0,     $101

        EIS                       ; enable interrupts

        MVII    #$200,  R4        ; R4 = pointer into backtab
        SDBD                      ; R5 = pointer into test cases
        MVII    #tc,    R5
        MVII    #13,    R3        ; R3 = number of test cases

@@loop  MVI@    R5,     R0        ; R0 = a
        MVI@    R5,     R1        ; R1 = b
        MVI@    R5,     R2        ; R2 = c
        PSHR    R3                ; save R3 and R5 on the stack
        PSHR    R5
        CALL    tr                ; invoke our routine
        PULR    R5                ; restore R3 and R5
        PULR    R3

        MVII    #$80,   R0        ; R0 = '0'
        BC      @@draw

        MVII    #$88,   R0        ; or '1' if the carry is not set

@@draw  MVO@    R0,     R4        ; draw this character

        DECR    R3                ; next test case
        BNEQ    @@loop

        DECR    R7                ; loop forever

        ;; ------------------------------------------------------------- ;;
        ;;  test cases                                                   ;;
        ;; ------------------------------------------------------------- ;;
tc      PROC

        DECLE   1, 1, 1           ; true
        DECLE   1, 2, 3           ; false
        DECLE   2, 1, 3           ; false
        DECLE   1, 3, 2           ; false
        DECLE   3, 2, 1           ; false
        DECLE   3, 1, 2           ; false
        DECLE   2, 2, 2           ; true
        DECLE   3, 4, 5           ; true
        DECLE   3, 5, 4           ; true
        DECLE   5, 3, 4           ; true
        DECLE   5, 4, 3           ; true
        DECLE   10, 9, 3          ; true
        DECLE   100, 10, 10       ; false

        ENDP

        ;; ------------------------------------------------------------- ;;
        ;;  ISR                                                          ;;
        ;; ------------------------------------------------------------- ;;
isr     PROC

        MVO     R0,     $0020     ; enable display

        CLRR    R0
        MVO     R0,     $0030     ; no horizontal delay
        MVO     R0,     $0031     ; no vertical delay
        MVO     R0,     $0032     ; no border extension
        MVII    #$D,    R0
        MVO     R0,     $0028     ; light-blue background
        MVO     R0,     $002C     ; light-blue border

        JR      R5                ; return from ISR

        ENDP

        ;; ------------------------------------------------------------- ;;
        ;;  our routine                                                  ;;
        ;; ------------------------------------------------------------- ;;
tr      PROC

        MOVR    R0,     R3        ; R3 = a
        ADDR    R1,     R3        ; R3 = a + b
        CMPR    R3,     R2        ; is R3 greater than c?
        ADCR    R7                ; if not, skip the next instruction

        ADDR    R2,     R3        ; R3 = a + b + c (or still a + b if skipped)
        SLL     R1                ; R1 = 2b
        CMPR    R3,     R1        ; is R3 greater than 2b?
        BC      @@rtn             ; if not, return with the carry set

        SLL     R0                ; R0 = 2a
        CMPR    R3,     R0        ; is R3 greater than 2a?
                                  ; if not, the carry is set

@@rtn   JR      R5                ; return

        ENDP

Output

output

screenshot from jzIntv


1. A CP-1610 opcode is encoded with a 10-bit value (0x000 to 0x3FF), known as a 'DECLE'.

Arnauld

Posted 2020-02-12T07:08:48.943

Reputation: 111 334

2+1 Marvelous :D – RGS – 2020-02-12T09:21:16.993

1Do you have to run this on your TV? Maybe an emulator is in order... – S.S. Anne – 2020-02-12T15:15:37.920

@S.S.Anne I'm doing 95% of the debugging on jzIntv. For real (much bigger) projects, I do upload the ROM to a real Intellivision from time to time.

– Arnauld – 2020-02-12T15:26:35.873

Oh, so that is an emulator. The homepage was unclear. – S.S. Anne – 2020-02-12T15:28:27.030

I think this should state that it is in machine language, not assembly language. I see that the assembler mnemonics alone are typically four bytes per instruction. PS. +1 Very nice. – Bit Chaser – 2020-02-12T18:20:57.097

@bitchaser That's a fair point. Updated! – Arnauld – 2020-02-12T18:35:02.660

9

Java 8, 52 49 38 26 bytes

(a,b,c)->a+b>c&a+c>b&b+c>a

Port of @xnor's formula turns out to be shorter after all, by taking the input as three loose integers instead of a List/array.
-12 bytes thanks to @xnor for reminding me that the first 6-bytes formula I used in my 05AB1E answer is actually shorter in Java:

\$(a+b>c)\land(a+c>b)\land(b+c>a)\$

Try it online.

Explanation:

(a,b,c)->  // Method with three integer parameters and boolean return-type
  a+b>c    //  Return whether the sum of a and b is larger than c
  &a+c>b   //  and the sum of a and c is larger than b
  &b+c>a   //  and the sum of b and c is larger than a

Previous 52 49 bytes answer:

S->{S.sort(null);return S.pop()<S.pop()+S.pop();}

Port of @GB's Ruby answer with input as a Stack of Integers.

Try it online.

Explanation:

S->{                        // Method with Integer-Stack parameter and boolean return-type
  S.sort(null);             //  Sort the input-Stack
  return S.pop()            //  Check if the last largest value
         <S.pop()+S.pop();} //  is smaller than the lowest two values added together

Kevin Cruijssen

Posted 2020-02-12T07:08:48.943

Reputation: 67 575

It is funny that even though you compute the max with a bunch of ?: operators, you can still get it to be shorter than the other answer! – RGS – 2020-02-12T13:20:20.303

1Wow! Just looking over the other answers and see we're letter for letter identical (save the C/Java diffs)! I swear I did mine on my own! T_T – Noodle9 – 2020-02-12T13:20:58.957

1

@RGS Yeah, and the ?: are actually shorter than using the Math.max builtin, since it can only take 2 arguments (Math.max(Math.max(a,b),Math.max(b,c)) is longer than (a>b?a>c?a:c:b>c?b:c)). PS: as List with builtin streams it's even longer: L->L.stream().mapToInt(i->i).sum()>L.stream().max((i,j)->i.compareTo(j)).get()*2 (80 bytes). That was my very first attempt, before I posted my answer and had the 51 bytes alternative. ;)

– Kevin Cruijssen – 2020-02-12T13:27:18.670

@KevinCruijssen the lengths you have to go to just to golf in Java!! – RGS – 2020-02-12T13:33:18.087

1

@RGS That's why it's so fun and I'm still here after almost four years of code-golfing. Although Java will never win a code-golf contest, tbh. Unless it's the only answer of course. ;P

– Kevin Cruijssen – 2020-02-12T13:36:30.543

@KevinCruijssen oh so you are saying you being around has nothing to do with your apparent obsession with puzzles? :D

– RGS – 2020-02-12T13:40:21.353

@RGS Tbh, twisty puzzles and code-golfing are completely different tbh. I'm pretty good in code-golfing, but not so good in solving puzzles, despite my enormous collection. I have to resort to tutorials pretty often, although I currently have loads of unsolved puzzles for which I'm either the only or one of the only owners, so no tutorial are available. Tbh, I also don't collect twisty puzzles as much as I used to and already sold a few. I'm more focused on some of my other collections lately. Basically too many hobbies, but not enough time and/or money. XD – Kevin Cruijssen – 2020-02-12T13:44:04.103

@KevinCruijssen I understand your pain :'( generally speaking – RGS – 2020-02-12T14:55:43.360

1

It looks like it's actually shorter to write out a+b>c&b+c>a&c+a>b: TIO

– xnor – 2020-02-12T23:53:46.947

@xnor Ah, of course.. I actually used that approach initially in my 05AB1E answer, haha.. Thanks for the reminder! – Kevin Cruijssen – 2020-02-13T07:42:45.217

7

Ruby, 19 bytes

->*a{2*a.max<a.sum}

You can try it online!

Uses the fact that this Ruby answer said it didn't want to implement the port of xnor's answer and at the same time taught me enough syntax to guess how the max of an array is calculated :)

RGS

Posted 2020-02-12T07:08:48.943

Reputation: 5 047

@S.S.Anne Please remember to follow the Code of Conduct.

– Doorknob – 2020-02-15T04:45:28.190

@Doorknob What did I do? – S.S. Anne – 2020-02-15T14:47:06.193

6

05AB1E, 6 5 4 bytes

O;‹ß

-1 byte by porting @xnor's algorithm.
-1 byte thanks to @Grimmy using a derived formula.

Try it online or verify all test cases.

Explanation:

The formula this program uses to determine if three side-lengths \$a,b,c\$ form a triangle is:

\$t=\frac{a+b+c}{2}\$
\$(a<t)\land(b<t)\land(c<t)\$

O     # Take the sum of the (implicit) input-list
 ;    # Halve it
  ‹   # Check if it's larger than each of the values of the (implicit) input-list
   ß  # Get the minimum of those checks
      # (`P` can be used as alternative to check if all are truthy instead)
      # (after which this result is output implicitly)

Original 6-byter:

ÀĆü+‹P

Try it online or verify all test cases.

Explanation:

The formula this program uses to determine if three side-lengths \$a,b,c\$ form a triangle is:

\$a+b>c\$
\$a+c>b\$
\$b+c>a\$

Which translates to the following code for 05AB1E:

À       # Rotate the (implicit) input-list once towards the right: [a,b,c] → [b,c,a]
 Ć      # Enclose it; appending its head to itself: [b,c,a] → [b,c,a,b]
  ü+    # Sum each overlapping pair: [b,c,a,b] → [b+c,c+a,a+b]
    ‹   # Check for each whether it's larger than the (implicit) input-list:
        #  [a<b+c,b<c+a,c<a+b]
     P  # And check if all three are truthy by taking the product
        # (`ß` could be used as alternative, like in the 4-byter program above)
        # (after which the result is output implicitly)

Kevin Cruijssen

Posted 2020-02-12T07:08:48.943

Reputation: 67 575

+1 simple enough, right? – RGS – 2020-02-12T07:21:15.360

Another alternative 5-byter: xsO‹ß

– Kevin Cruijssen – 2020-02-12T13:31:55.400

3O;‹ß is 4 bytes. – Grimmy – 2020-02-12T14:50:04.930

@Grimmy Ah smart, thanks! – Kevin Cruijssen – 2020-02-12T15:05:00.930

6

Ruby, 23 bytes

->*a{a.sort!.pop<a.sum}

Try it online!

A different approach, xnor's formula would be shorter but I'm satisfied with that.

G B

Posted 2020-02-12T07:08:48.943

Reputation: 11 099

+1, I'll take it then :)

– RGS – 2020-02-12T08:53:07.533

6

PHP, 45 32 bytes

fn($a)=>max($a)*2<array_sum($a);

Try it online!

Lambda function that takes an array [a, b, c] and outputs empty string if false or "1" if true, with xnor's formula.

Note that in PHP the ; is only necessary when the function is attributed to a variable, so it's placed in the footer (provided code is valid as it is).

EDIT: thanks to Guillermo Phillips for introducing me to PHP 7.4 short notation! (as a declaration without {}, it now needs the ;)

Kaddath

Posted 2020-02-12T07:08:48.943

Reputation: 449

1Could you not use the short lambda syntax from PHP 7.4? – Guillermo Phillips – 2020-02-12T10:25:33.693

@GuillermoPhillips thanks a lot, I actually didn't know them, it doesn't appear on the manual (yet?) – Kaddath – 2020-02-12T10:32:06.643

Good job on this PHP answer and +1 for this lambda function! – RGS – 2020-02-12T13:15:06.677

6

J42161217

Posted 2020-02-12T07:08:48.943

Reputation: 15 931

Thanks for teaching me smth! I'm assuming (1): the single @ can be used to call a function and (2): the trace of a list is its sum. Am I right? – RGS – 2020-02-12T13:31:36.600

@RGS Yup! and here are some "master tips"... https://codegolf.stackexchange.com/q/12900/67961

– J42161217 – 2020-02-12T14:32:53.153

6

C (gcc), 30 bytes

Probably the most basic formula.

f(a,b,c){a=a+b>c&a+c>b&b+c>a;}

Try it online!

Arnauld

Posted 2020-02-12T07:08:48.943

Reputation: 111 334

Good job recognising the more verbose formula ends up being shorter here! What is the leading a=? Is it for some kind of implicit return? – RGS – 2020-02-12T18:39:06.460

2

@RGS Yes. The way gcc compiles this, assigning the value to a variable or returning it both put the result in eax and therefore lead to the same behavior.

– Arnauld – 2020-02-12T19:16:52.027

2I learned so much of C from this answer. I didn't know you could omit the type of parameters, return type, and return statement. – user1754322 – 2020-02-15T11:38:42.873

1@user1754322 Just remember to only use it in code golf. This is formally undefined behavior in every C standard. – S.S. Anne – 2020-02-15T14:49:42.713

5

APL (Dyalog Unicode), 7 bytesSBCS

+/>2×⌈/

Try it online!

Also uses xnor's formula of sum(a,b,c) > 2 * max(a,b,c).

How it works

+/>2×⌈/
+/       ⍝ Is sum
  >      ⍝ greater than
   2×    ⍝ twice of
     ⌈/  ⍝ max?

Alternative 7 bytesSBCS

∧/+/>+⍨

Try it online!

How it works

∧/+/>+⍨
  +/     ⍝ Is sum
    >    ⍝ greater than
     +⍨  ⍝ twice each number?
∧/       ⍝ All of them?

Bubbler

Posted 2020-02-12T07:08:48.943

Reputation: 16 616

1Thanks for the submission +1 what is up with the weird character you are using in the explanations? – RGS – 2020-02-12T08:11:18.313

3@RGS If you mean , it starts a line comment in APL (just like // in C and # in Python). – Bubbler – 2020-02-12T08:15:38.923

1@Bubbler But only C99 and after. It's commonly called a "C++-style comment". – S.S. Anne – 2020-02-12T15:16:32.820

5

GolfScript, 5 bytes

$~\->

Why bother with any of the other math? If the longest side is longer (or equal) than the sum of the shorter two, it can't be a triangle. Otherwise it can.

Input is an array. Output is 0 or 1. If you have the list necessarily sorted, then you can just input as a dumped array (straight onto the stack) and the first two characters are unneeded. If the list can be entered in reverse order, then you can remove the first three characters and flip the greater-than to a lesser-than, leaving only 2 characters needed.

$~\->  #Check if side lengths could make a triangle
$      #Sort
 ~     #Dump array onto stack (stack is now 1 2 3)
  \    #Swap the top two elements (1 3 2)
   -   #Subtract the top from the second (1 3-2)
    >  #Check if that difference is strictly greater than the smallest value

This is equivalent to my last answer, but instead of a+b>c, I did a>c-b, which saves a character of stack-shuffling.

Try it online!

Mathgeek

Posted 2020-02-12T07:08:48.943

Reputation: 408

3you are still using maths :D good job on this! – RGS – 2020-02-12T13:32:35.867

4

Jelly, 4 bytes

ṀḤ<S

Try it online!

A monadic link taking a list of integers and returning a Jelly boolean (1 = True, 0 = False).

Based on @xnor's Python answer so be sure to upvote that one too!

Explanation

Ṁ    | Maximum
 Ḥ   | Doubled
  <  | Less than:
   S | - Sum of original argument

Nick Kennedy

Posted 2020-02-12T07:08:48.943

Reputation: 11 829

1+1 good job on the port :) – RGS – 2020-02-12T08:48:58.617

2@RGS thanks. Nice series of questions recently! – Nick Kennedy – 2020-02-12T08:51:26.070

thanks for your feedback, let's keep them coming! – RGS – 2020-02-12T08:57:39.583

1

Alternative 4 bytes: Ḥ<SẠ for "double of all elements less than sum".

– Bubbler – 2020-02-12T09:05:07.907

4

Retina 0.8.2, 31 bytes

\d+
$*
O`1+
^(?!(1+),(1+),\1\2)

Try it online! Link includes test cases. Explanation:

\d+
$*

Convert to unary.

O`1+

Sort.

^(?!(1+),(1+),\1\2)

Check that the sum of the first two is greater than the third.

Neil

Posted 2020-02-12T07:08:48.943

Reputation: 95 035

These Retina solutions keep amusing me! +1 – RGS – 2020-02-12T13:17:19.390

1@RGS It's always nice when you can coax Retina to perform functions which seem unrelated to string manipulation. – Neil – 2020-02-13T10:06:09.880

Indeed!!! Now I want to see how Retina fares in the count regex matches challenge, which is related to string manipulation!

– RGS – 2020-02-13T11:28:52.400

1@RGS I can't see an obvious approach for that one sorry. – Neil – 2020-02-13T18:47:57.877

4

C (gcc), 54 \$\cdots\$ 46 42 bytes

f(a,b,c){a=a+b+c>2*(a>b?a>c?a:c:b>c?b:c);}

Try it online!

Uses xnor's formula.

Noodle9

Posted 2020-02-12T07:08:48.943

Reputation: 2 776

1Obvious +1 for having the same answer. ;) – Kevin Cruijssen – 2020-02-12T13:23:04.363

@KevinCruijssen Likewise my good man. :-) – Noodle9 – 2020-02-12T13:33:01.273

You can use the same golf as my Java answer (credit to @xnor): f(a,b,c){a=a+b>c&a+c>b&b+c>a;} EDIT: Nvm, @Arnauld already posted that as a separated C answer. – Kevin Cruijssen – 2020-02-13T07:43:47.717

@KevinCruijssen Ah, interesting! Ok, I'll stick with what I've got - thanks anyway! :-) – Noodle9 – 2020-02-13T09:49:46.547

3

Lua, 128 120 bytes

b=io.read()t={}for r in b.gmatch(b,"([^,]+)")do
table.insert(t,r) end
print(t[1]+t[2]+t[3]+0>math.max(t[1],t[2],t[3])*2)

Try it online!

Lua, 37 bytes

@Jo King's solution using TIO properly and following the rules of the challenge.

a,b,c=...print(a+b+c>math.max(...)*2)

Try it online!

Very direct translation of @xnor's algorithm

ouflak

Posted 2020-02-12T07:08:48.943

Reputation: 925

Hey there, if I understand correctly, you are spending quite some bytes reading from input and extracting the integers. Can't you define a shorter function that already takes the integers? And then you do the IO parsing in the header section of TIO? – RGS – 2020-02-12T08:48:17.430

@RGS, Yes, absolutely. I can post a solution like that in the comments. Just gimmee a bit.... – ouflak – 2020-02-12T08:49:57.403

no need to be in the comments! Rewrite your answer. In this community, and for code-golf, you can usually just write the function that does what is asked, as long as your function accepts the input as specified by the OP. I can't really elaborate on it now nor exemplify with Lua because I don't know lua, but I'm sure you can reduce your byte count by a lot if you do what I mean – RGS – 2020-02-12T08:57:01.907

@JoKing, I've really got do some study and wrap my head around how to use TIO's header properly. – ouflak – 2020-02-13T11:51:49.470

3

Burlesque, 13 bytes

raJ++j>]2.*.>

Try it online!

ra # Read as array
J  # Duplicate
++ # Sum
j  # Swap
>] # Maximum
2.*# Double
.> # Greater than

DeathIncarnate

Posted 2020-02-12T07:08:48.943

Reputation: 916

+1 good job working on this :) – RGS – 2020-02-12T08:58:58.807

3

Wren, 54 bytes

I haven't written Wren in a long time...

Fn.new{|x|x.reduce{|a,b|a+b}>x.reduce{|a,b|a>b?a:b}*2}

Try it online!

a'_'

Posted 2020-02-12T07:08:48.943

Reputation: 1 099

I have never seen Wren around here, for the short time I've been around – RGS – 2020-02-12T13:25:07.220

3

C (gcc), 40 bytes

-2 bytes thanks to Arnauld: stores the result of max in a. Eliminates the variable m used in the previous solution.

f(a,b,c){a=a+b+c>2*((a=a>b?a:b)>c?a:c);}

Try it online!

C (gcc), 42 bytes

f(a,b,c){a=a+b+c>2*(a>b?a>c?a:c:b>c?b:c);}

Try it online!

S.S. Anne

Posted 2020-02-12T07:08:48.943

Reputation: 1 161

Good solution +1! It is a shame that the m doesn't save you anything... – RGS – 2020-02-12T15:06:15.670

3

C++ (gcc), 89 bytes

Array/vector solution as shown in other answers.

#import<regex>
int f(std::vector<int>v){std::sort(&v[0],&*end(v));return v[2]<v[1]+v[0];}

Try it online!

C++ (gcc), 56 bytes

int f(int a,int b,int c){a=a+b+c>2*((a=a>b?a:b)>c?a:c);}

Like the C solution but with more boilerplate.

-2 bytes thanks (indirectly) to Arnauld!

Try it online!

S.S. Anne

Posted 2020-02-12T07:08:48.943

Reputation: 1 161

Good job on this one! +1 can you please explain me why you need the #import? – RGS – 2020-02-12T15:56:06.877

@RGS Because functions (like std::sort) are not implicitly declared in C++, and std::vector is not a builtin. – S.S. Anne – 2020-02-12T16:22:32.310

3

Never done one of these before. Here are two algorithms borrowed from other answers implemented in JavaScript.

JavaScript, 32 bytes

(a,b,c)=>a+b+c>Math.max(a,b,c)*2

Try it online

JavaScript, 28 bytes

(a,b,c)=>a=a+b>c&a+c>b&b+c>a

Try it online

James Coyle

Posted 2020-02-12T07:08:48.943

Reputation: 131

1Really good job James! +1 And welcome to the site :D – RGS – 2020-02-13T11:48:17.627

3

Pepe, 93 bytes

REeEREeEREeEREEEEeEeEREEEeREEEEEEEREEEEEEEErREEEEEerEEEEEerEeEeErEEEEeeRErREErEEEEeREeReEreEE

Input: a;b;c
Output: -1 for falsy, 1 for truthy

Explanation:

REeEREeEREeE # Push 3 inputs (num) -> (R)
REEEEeEeE # Sort the (R) stack
REEEe # Move pointer pos to the last -> (R)
REEEEEEE # Move last item of (R) (num c in this case) to (r)
REEEEEEEE # Sum the stack (note: does not remove the stack completely!) -> (R)
          # For some reason, the pointer pos of (R) keeps sticking to the last item
rREEEEEe # Subtract active item of (R) (a+b) to (r) (num c) -> (R)
         # ((a+b)-c)
         # r flag: Preserve the items
rEEEEEe # Same as above, but put it to (r)
        # This switches the expression: (c-(a+b)) or -((a+b)-c)
        # No more r flag this time, so remove these two items
rEeEeE # Absolute of (r)
rEEEEee # Divide active item of (R) (a+b) and (r) (num c) -> (r)
RE # Push 0 -> (R)
rREE # Create loop labelled 0 -> (R)
     # r flag: Skip until Ee (or REe)
  rEEEEe # Decrement (0 -> -1) -> (r)
  REe # Return to where a goto was called last
ReE # If the division of (r) returned 0, go inside the loop
reEE # Output (r) as number

Try it online!

u_ndefined

Posted 2020-02-12T07:08:48.943

Reputation: 1 253

Really funny solution! +1 good job! – RGS – 2020-02-15T08:30:22.957

2

MathGolf, 5 bytes

Σ\╙∞>

Try it online.

Exact port, including same explanation, as my 5-byte 05AB1E answer: sum; swap; max; double; a>b.

Kevin Cruijssen

Posted 2020-02-12T07:08:48.943

Reputation: 67 575

But in this case, it is shorter! – RGS – 2020-02-12T08:12:21.060

@RGS What do you mean? Both are 5 bytes, and the exact same explanation. – Kevin Cruijssen – 2020-02-12T08:14:16.267

I meant your original O5AB1E one was 6 bytes :p – RGS – 2020-02-12T08:45:42.843

2

J, 8 bytes

+/>2*>./

Try it online!

Uses xnor's formula

Galen Ivanov

Posted 2020-02-12T07:08:48.943

Reputation: 13 815

+1 simple port, right? :) – RGS – 2020-02-12T08:12:37.007

1@RGS Yes, it's almost identical to Bubbler's APL solution - it's normal, J is APL's relative. – Galen Ivanov – 2020-02-12T08:30:18.943

2

GolfScript, 14 bytes

A port of the Ruby answers.

~.{+}*\$)\;2*>

Try it online!

Explanation

~              # Evaluate the input
 .             # Copy it twice
  {+}*         # Sum the input
      \$       # Sort the other input
        )\;    # Select the last item
               # in the sorted list
           2*  # Double this item 
             > # Compare

a'_'

Posted 2020-02-12T07:08:48.943

Reputation: 1 099

Good job on this answer! – RGS – 2020-02-12T13:22:20.347

2

W d, 12 10 bytes

I'm quite satisfied because W doesn't have a max function. OR a function sorting the array.

▼╪m╜w♣S×∟╖

Uncompressed:

<a&b|R       % Max.
      2*     % Double.
        S    % Swap.
         +r  % Sum.
           < % Less than.
% It's in the wrong order because
% I can golf a few bytes off the max function.
% BTW the max function is implemented like this:
(b<a) && (a) || (b)
% The reduction reduces this function over the whole list.

a'_'

Posted 2020-02-12T07:08:48.943

Reputation: 1 099

1Impressive first answer and very well presented. welcome! – J42161217 – 2020-02-12T12:35:57.607

@J42161217 ditto! – RGS – 2020-02-12T13:27:07.830

3I feel like there was another higher-up user named a'_' that went missing recently. Hmm... – S.S. Anne – 2020-02-12T14:53:49.953

2

Keg, -hr, 7 5 bytes

÷⑭$->

Try it online!

Woot! Port of the 5-byte golfscript answer. TIO won't work because the version stored has a bug with the command, while the most recent version doesn't. (For those interested, I believe TIO is ~20 commits behind the official repo).

This gets converted into the following python program:

from KegLib import *
from Stackd import Stack
stack = Stack()
printed = False
item_split(stack)
sort_stack(stack)
swap(stack)
maths(stack, '-')
comparative(stack, '>')
if not printed:
    raw(stack)

Explained

÷

First, we take the sides as input. Keg doesn't do lists very well at the moment (I'm working on improving that though), so each number needs to be taken individually. The ¿ takes the input and evaluates it as a literal. Forget I ever said that. One can actually take a list as input lol. So instead of taking three individual numbers, we go ahead and item split the implicit input list.

⑭$->

Then, like the golfscript answer, we sort the stack (), swap the top two items ($) subtract those two items (-) and then finally compare the two with >.

Lyxal

Posted 2020-02-12T07:08:48.943

Reputation: 5 253

1Kool answer! +1 To bad you have to spend three bytes reading the integers! – RGS – 2020-02-12T23:11:09.270

@RGS whatever do you mean by spending three bytes to read the integers? :P – Lyxal – 2020-02-12T23:14:46.190

Nevermind me :) Can't upvote anymore today :( will try to remember to do it tomorrow! – RGS – 2020-02-12T23:19:28.123

@RGS I know that feeling :P. – Lyxal – 2020-02-12T23:20:18.550

one up!! Go work on those lists now!!! – RGS – 2020-02-13T00:41:38.263

2

Stax, 7 bytes

å·b→1.R

Run and debug it

a'_'

Posted 2020-02-12T07:08:48.943

Reputation: 1 099

Haven't heard of Stax before! Good work on this +1 – RGS – 2020-02-13T08:36:43.540

2

x86-16 machine code, 21 bytes

8B D0       MOV  DX, AX     ; DX = a 
03 C3       ADD  AX, BX     ; AX = a + b 
3B C1       CMP  AX, CX     ; is a + b > c? 
76 0C       JBE  NOT_TRI    ; if so, not triangle 
03 C1       ADD  AX, CX     ; AX = a + b + c 
D1 E2       SHL  DX, 1      ; DX = 2a 
3B C2       CMP  AX, DX     ; is a + b + c > 2a? 
76 04       JBE  NOT_TRI    ; if so, not triangle 
D1 E3       SHL  BX, 1      ; BX = 2b 
3B C3       CMP  AX, BX     ; is a + b + c > 2b? 
        NOT_TRI:
C3          RET             ; return to caller

Callable function, input AX, BX and CX. Result is in ZF: NZ if triangle, ZR if not.

Uses Arnauld's method to check.

I/O from DOS test program: enter image description here

For some reason the test program returns "Hotdog" if a triangle and "Not Hotdog" if not.

640KB

Posted 2020-02-12T07:08:48.943

Reputation: 7 149

1Nice submission! Are you being serious with the "for some reason" or did you make the program return (not) hot dog for Truthy and Falsy? :) – RGS – 2020-02-15T21:50:01.420

@RGS okay, you got me, maybe it was kinda intentional.

– 640KB – 2020-02-16T14:49:08.927

1

Perl 5 -alp -MList::Util=max,sum, 18 bytes

$_=sum(@F)>2*max@F

Try it online!

Perl 5 -alp, 32 bytes

Otherwise without imports

/ .* /;$_=!grep$_*2>=$`+$&+$',@F

Try it online!

Nahuel Fouilleul

Posted 2020-02-12T07:08:48.943

Reputation: 5 582

+1 for your answer, and I had never seen people doing "imports" with flags! Amusing :D even though it feels unfair :( – RGS – 2020-02-12T08:12:01.917

iv'e added another answer without using imports – Nahuel Fouilleul – 2020-02-12T11:37:50.630

you are welcome to use "imports" in the flags! I was just thinking it is quite nice that you can "get away" with it :) – RGS – 2020-02-12T13:23:37.510

1

Red, 31 bytes

func[a][(sum sort a)>(2 * a/3)]

Try it online!

A port of @xnor's algorithm

Thanks to S.S. Anne for finding an unnecessary newline!

Galen Ivanov

Posted 2020-02-12T07:08:48.943

Reputation: 13 815

Is a/3 the third element of a? Because it looks like you are dividing by 3 :O – RGS – 2020-02-12T13:24:49.977

1@RGS Haha, yes - it really is the third element (notice the lack of spaces around /) This is path notation in Red, used for indexing, navigation in hierachical structures, map keys, object fields and so on. – Galen Ivanov – 2020-02-12T13:31:32.320

1thanks for the clarification! – RGS – 2020-02-12T13:33:42.820

131 without the trailing newline. – S.S. Anne – 2020-02-12T15:12:30.120

@S.S. Anne Thanks! – Galen Ivanov – 2020-02-12T15:48:57.053

1

Japt -e, 5 bytes

Ñ<NÎx

Try it online.

Shaggy

Posted 2020-02-12T07:08:48.943

Reputation: 24 623

for a simple answer. What does "transpiled JS" mean in the Japt console? (Btw looks like the cockpit for a spaceship! +1) – RGS – 2020-02-12T13:29:34.583

No, it needs to be UNIX. – S.S. Anne – 2020-02-12T15:09:07.357

1

Pyth, 8 6 bytes

<yeSQs

Kinda unfortunate that pop is two bytes :'(

Saved 2 bytes thanks to @RGS

Try it online!

famous1622

Posted 2020-02-12T07:08:48.943

Reputation: 451

Good job on the Pyth answer, but then wouldn't it be better to use this formula?

– RGS – 2020-02-12T15:19:32.533

@RGS Not sure how I missed that, saved 2 bytes, thanks! – famous1622 – 2020-02-12T16:26:39.147

1

Charcoal, 6 bytes

›Σθ⊗⌈θ

Try it online! Link is to verbose version of code. Takes input as an array and outputs a Charcoal boolean, i.e. - for true, nothing for false. Uses @xnor's algorithm. Explanation:

  θ     Input array
 Σ      Summed
›       Is greater than
     θ  Input array
    ⌈   Maximum
   ⊗    Doubled
        Implicitly print

Neil

Posted 2020-02-12T07:08:48.943

Reputation: 95 035

+1 for your work, isn't there a way for you to shave one of the θ by using the input implicitly as the argument? – RGS – 2020-02-13T11:27:46.680

1@RGS Maybe, but not in verbose mode, I don't think. – Neil – 2020-02-13T12:04:09.560

1

T-SQL, 29 bytes

Returns 1 for true and 0 for false

DECLARE @ table(x INT)
INSERT @ values(1),(1),(1)


SELECT-sum(x)/~max(2*x)FROM @

t-clausen.dk

Posted 2020-02-12T07:08:48.943

Reputation: 2 874

Interesting submission! +1 for that :) – RGS – 2020-02-15T21:48:53.347

1

Excel, 20 bytes

=SUM(A:A)>MAX(A:A)*2

Input in A1, A2 and A3.


Alternatively, with input on A1, B1 and C1:

=SUM(1:1)>MAX(1:1)*2

Wernisch

Posted 2020-02-12T07:08:48.943

Reputation: 2 534

Cool submission! :D +1 – RGS – 2020-02-14T12:46:03.157

1

R, 26 bytes

function(x)sum(x)>2*max(x)

Try it online!

If the sum of 3 numbers is greater than twice the greater of those numbers, then the triangular inequality holds.

Rui Barradas

Posted 2020-02-12T07:08:48.943

Reputation: 131

De facto! Thanks for the R submission! +1 – RGS – 2020-02-15T21:48:32.573

1

Julia 1.0, 20 bytes

f(s)=all(sum(s).>2s)

Try it online!

Glen O

Posted 2020-02-12T07:08:48.943

Reputation: 2 548

Nice and simple Julia submission +1 :) – RGS – 2020-02-17T08:03:31.050