Rules
Given a list of integer coordinates, l, with a length of at least 4, and an integer n such that n is smaller than the length of l (but at least 3), return the largest area of an n-sided polygon satisfies:
- is simple (not self-intersecting).
- has all the coordinates of its n vertices in the list l.
- has no three consecutive collinear vertices.
Note that the polygon given in the input should comply to the three points above as well.
Test Cases
Here are a few test cases:
[(0,0), (0,-1), (-1,-1), (-1,0)], 3 -> 0.5
[(0,0), (1,0), (2,1), (2,2), (1,3), (0,3), (-1,2), (-1,1)], 3 -> 3
[(0,0), (1,0), (2,1), (2,2), (1,3), (0,3), (-1,2), (-1,1)], 5 -> 5.5
[(0,0), (1,0), (2,1), (2,2), (1,3), (0,3), (-1,2), (-1,1)], 6 -> 6
You can try any test cases you like here.
Make your code as short as possible.
n
is small but|l|
is much larger. The link to generate more test cases is useful for getting more should we need them. I don't have any good insight on this problem, other than that the likely algorithms are going to be the brute forceO(|l|^n)
\$\endgroup\$