Skip to the content

Is it isosceles?

Problem

A triangle is isosceles if at least two of its sides are the same length. Write a function that takes a list with the three sides and returns true if that triangle is isosceles, and false if it isn't. With 5, 5 and 8 you return true, because two sides match. With 6, 7 and 8 you return false: all three are different.

Before comparing, check that the triangle exists. Every side has to be shorter than the other two together: with 1, 1 and 3 the two short sides can't reach the long one, so there is no triangle there and you return false, even though two sides are the same. And if one side is exactly as long as the other two together, like 2, 2 and 4, the three of them lie flat in a straight line: no triangle either.

Two more notes: a triangle with all three sides equal is isosceles too, because "at least two" includes three, and the sides may come with decimals. Three of them always arrive, and always positive.

Examples

  • First two sides are equal

    [4, 4, 3] → true

  • All three sides are different

    [2, 3, 4] → false

  • Two equal sides, but no triangle

    [1, 1, 3] → false

Besides these, the challenge has hidden tests that are revealed when you submit your solution.

You start with this

Python

def is_isosceles(sides):
    pass

JavaScript

function isIsosceles(sides) {
}
Solve this challenge

It opens in your browser, with the editor and the tests. It is free and you do not need an account to start.

More O(1) challenges

See all challenges →