Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
in any lights solution in Clear category for Searchlights by kurosawa4434
from math import sin, cos, radians, hypot
def searchlights(polygons, lights):
def vertices():
for x, y, edge, v in polygons:
for i in range(v):
rad = radians((270-90*(v-2)/v) + 360/v*i)
x += cos(rad) * edge
y += sin(rad) * edge
yield x, y
return sum(any(r >= hypot(x-cx, y-cy) for cx, cy, r in lights)
for x, y in vertices() if x >= 0 and y >= 0)
if __name__ == '__main__':
print("Example:")
print (searchlights([(2, 3, 2, 3)], [(1, 2, 1)]))
# These "asserts" are used for self-checking and not for an auto-testing
assert(searchlights([(2, 3, 2, 3)], [(1, 2, 1)])) == 1, 'regular triangle'
assert(searchlights([(4, 5, 2, 4)], [(4, 4, 3)])) == 4, 'square'
assert(searchlights([(6, 7, 2, 5)], [(2, 3, 2)])) == 0, 'regular pentagon'
assert(searchlights([(4, 2, 2, 6)], [(4, 2, 3)])) == 3, 'regular hexagon'
assert(searchlights([(1, 7, 2, 8)], [(0, 5, 4)])) == 5, 'regular octagon'
print("Coding complete? Click 'Check' to earn cool rewards!")
Nov. 29, 2019