#296 · Geometry · Intermediate · 70 XP · about 12 min
A surveyor walks once around the border of a plot of land and writes down each corner as an (x, y) tuple of integers, in the order she reaches them. She may walk clockwise or counter-clockwise, and the border never crosses or touches itself.
Write polygon_area(points) that returns the area of the plot as a float.
polygon_area([(0, 0), (4, 0), (4, 3), (0, 3)]) # returns 12.0 polygon_area([(0, 0), (3, 0), (0, 5)]) # returns 7.5 polygon_area([(1, 1), (1, 4), (2, 4), (2, 2), (5, 2), (5, 1)]) # returns 6.0
The last plot is L-shaped and listed clockwise: an upright 1 by 3 strip and a 3 by 1 strip, area 6.
With whole-number corners, every area is a whole number or a whole number and a half, so the float is exact.
First solves only, ranked by stars and then time.