Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
11-liner: simple solution in Clear category for Searchlights by przemyslaw.daniel
from math import pi, sin, cos, hypot
def searchlights(polygons, lights):
result = 0
for xp, yp, length, sides in polygons:
for index in range(sides):
if any(hypot(x-xp, y-yp) <= radius for x, y, radius in lights):
result += xp >= 0 and yp >= 0
xp -= length*cos((1+index*2)*pi/sides)
yp -= length*sin((1+index*2)*pi/sides)
return result
Nov. 21, 2019