A Possible Shape?

Published by Matt in

Given the number n and an array of interior angles angles, return whether or not it's possible to make a polygon with n sides with the angles given. Remember that angles must be under 180°.

is_shape_possible(3, [80, 70, 30]) ➞ true

Triangle with the angles 80, 70 and 30

A shape with 3 sides and the angles 80°, 70° and 30° is a possible shape.

Examples

is_shape_possible(4, [90, 90, 90, 90]) ➞ true

is_shape_possible(3, [20, 20, 140]) ➞ true

is_shape_possible(1, [21]) ➞ false
# n must be larger than 2

is_shape_possible(5, [500, 10, 10, 10, 10]) ➞ false
# You can't have an interior angle bigger than 180°

Notes

  • Return false if n is less than 3 (see example #3).
  • There will always be an n number of positive integers given as angles.
  • The sum of interior angles is (n - 2) x 180°.
Watch a quick demo on how Edabit works.