In this post, we will solve **Compute the Perimeter of a Polygon HackerRank Solution**. This problem** (Compute the Perimeter of a Polygon)** is a part of **HackerRank Functional Programming** series.

Contents

**Task**

You are given the cartesian coordinates of a set of points in aÂ **2D**Â plane. When traversed sequentially, these points form a Polygon,Â * P*, which is not self-intersecting in nature. Can you compute the perimeter of polygonÂ

*?*

**P****Input Format**

The first line contains an integer,Â * N*, denoting the number of points.

TheÂ

*Â subsequent lines each containÂ*

**N****2**Â space-separated integers denoting the respectiveÂ

*Â andÂ*

**x***Â coordinates of a point.*

**y****Constraints**

- NoÂ
**2**Â points areÂ*coincident*, and polygonÂÂ is obtained by traversing the points in a clockwise direction.**P** **3 <=***N*<= 1000**0 <=***x*,*y*<= 1000

**Output Format**

For each test case, print the perimeter ofÂ * P*Â (correct to a scale of one decimal place).

**Note:**Â Do not add any leading/trailing spaces or units.

**Sample Input**

```
4
0 0
0 1
1 1
1 0
```

**Sample Output**

`4`

**Explanation**

The given polygon is a square, and each of its sides areÂ **1**Â unit in length.Â ** perimeter(P) = 1 + 1 + 1 + 1 = 4**, so we printÂ

**4**Â on a new line.

**Solution – Compute the Perimeter of a Polygon – HackerRank Solution**

**Haskell**

d [x,y,x1,y1] = sqrt $ (x1 - x)^2 + (y1 - y)^2 d _ = 0 p [] acc = acc p points acc = p (drop 2 points) (acc + (d (take 4 points))) perimeter points = p (points ++ (take 2 points)) 0 main :: IO () main = do _ <- getLine x <- getContents let f = map read $ words x print $ perimeter f

**Note:** This problem **(Compute the Perimeter of a Polygon)** is generated by **HackerRank** but the solution is provided by **CodingBroz**. This tutorial is only for **Educational** and **Learning** purpose.