Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Convex Hull by LMAO
def checkio(data):
def cross(o, a, b):
return (a[0] - o[0]) * (b[1] - o[1]) - (a[1] - o[1]) * (b[0] - o[0])
def hull(points):
hull = []
for p in points:
while len(hull) >= 2 and cross(hull[-2], hull[-1], p) > 0:
hull.pop()
hull.append(p)
return hull
points = sorted(data)
upper = hull(points)
lower = hull(reversed(points))
return [data.index(point) for point in upper[:-1] + lower[:-1]]
Feb. 27, 2015