Triangle Challenge

Published by Mubashir Hassan in

Given the perimeter and the area of a triangle, devise a function that returns the length of the sides of all triangles that fit those specifications. The length of the sides must be integers. Sort results in ascending order.

triangle(perimeter, area) ➞ [[s1, s2, s3]]

Examples

triangle(12, 6) ➞ [[3, 4, 5]]

triangle(45, 97.42786) ➞ [[15, 15, 15]]

triangle(70, 210) ➞ [[17, 25, 28], [20, 21, 29]]

triangle(3, 0.43301) ➞ [[1, 1, 1]]

Notes

  • Area is rounded to hundred thousandth (5 decimal places).
  • e.g. 59.444441 would round to 59.44444.
Watch a quick demo on how Edabit works.