Coming soon - Get a detailed view of why an account is flagged as spam!
view details

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

3
Help with function for perimeter of polygon
Post Body

dist :: Floating a => (a, a) -> (a, a) -> a
dist (i, j) (m, n) = sqrt ((i-m)^2   (j-n)^2)

zip' :: Floating a => [a] -> [(a,a)]
zip' []        =  []
zip' (x:[])    =  []
zip' (x:y:ys)  =  ((x,y):zip' ys)

perimeter :: Floating a => [(a, a)] -> a
perimeter [] = 0
perimeter (x:[]) = 0
perimeter (x:y:ys) = dist x y   perimeter (y:ys)

so suppose we have a list lst = [ (x1,y1) , (x2, y2) , (x3, y3), (x4, y4) ]. I know what my perimeter function does is basically:

dist (x1,y1) (x2,y2)   perimeter [(x2, y2),(x3, y3),(x4,y4)]
dist (x1,y1) (x2,y2)   dist (x2,y2) (x3,y3)   perimeter [(x3,y3),(x4,y4)]
dist (x1,y1) (x2,y2)   dist (x2,y2) (x3,y3)   dist (x3,y3) (x4, y4) perimeter [(x4,y4)]

now in order to make the perimeter complete, ideally somehow if we're given the original list x:y:ys then perimeter(z:[]) = dist x z (in other words, head of original list last of original list). So in our specific case, we'd end with:

 dist a b   dist b c   dist c d   dist d a

but I'm at a loss on how to get this to work. I'm sure it's something very simple. Any hints or suggestions would be much appreciate

Author
Account Strength
90%
Account Age
5 years
Verified Email
No
Verified Flair
No
Total Karma
5,316
Link Karma
1,027
Comment Karma
4,095
Profile updated: 1 day ago
Posts updated: 3 weeks ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
2 years ago