Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
It was my understanding that there would be no math solution in Clear category for Searchlights by HeNeArKr
import math
def searchlights(polygons, lights):
""" Return number of vertices of regular polygons described in 'polygons'
that fall within the radius of circles described in 'lights'.
"""
# Find all polygon vertices as equally spaced points around a circle
vertices = []
for x1, y1, length, sides in polygons:
theta = 2 * math.pi / sides # internal angle
r = length / (2 * math.sin(theta / 2))
x0, y0 = x1, y1 - r # center of polygon
for n in range(sides):
xp = x0 + r * math.cos(n * theta + math.pi / 2)
yp = y0 + r * math.sin(n * theta + math.pi / 2)
if xp > 0 and yp > 0: # as per mission notes
vertices.append((xp, yp))
# Count vertices within searchlights
return sum(any((xv - xc)**2 + (yv - yc)**2 <= rc**2
for xc, yc, rc in lights) for xv, yv in vertices)
Nov. 19, 2019
Comments: