Geometry 3: Perimeter of a Triangle

Published by Mateusz Mędrowski in

Write a function that takes the coordinates of three points and returns the perimeter of the triangle. The given points are the vertices of a triangle on a two-dimensional plane.

Examples

perimeter(arr[0]={15, 7}, arr[1]={5, 22}, arr[2]={11, 1}) ➞ 47.08

perimeter(arr[0]={0, 0}, arr[1]={0, 1}, arr[2]={1, 0}) ➞ 3.41

perimeter(arr[0]={-10, -10}, arr[1]={10, 10}, arr[2]={-10, 10}) ➞ 68.28

Notes

  • The given points always create a triangle.
  • The numbers in the argument array can be positive or negative.
  • There is 0.1 tolerance, so you don't need to round your result.
  • This challenge is easier than it looks.

Check my profile for other challenges in this series.

Watch a quick demo on how Edabit works.