Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Circumambulating solution in Uncategorized category for Four To The Floor by mpudup
import math
def is_covered(room, sensors):
width = room[0]
height = room[1]
numberSensors = len(sensors)
delta = width/100000
sweepStep = 0.000174
for N in range(numberSensors):
x_center = sensors[N][0]
y_center = sensors[N][1]
radius = sensors[N][2]
for theta in range(0,36000):
x = x_center + (radius+delta)*math.cos(theta*sweepStep)
y = y_center + (radius+delta)*math.sin(theta*sweepStep)
if (x >=0 and x <= width) and (y >=0 and y <= height):
checkOtherCircles = False
for k in range(N):
if (sensors[k][0]-x)**2 + (sensors[k][1]-y)**2 <= sensors[k][2]**2:
checkOtherCircles = True
for k in range(N,numberSensors):
if (sensors[k][0]-x)**2 + (sensors[k][1]-y)**2 <= sensors[k][2]**2:
checkOtherCircles = True
if not checkOtherCircles:
return False
return True
if __name__ == '__main__':
print("Example:")
print(is_covered([200, 150], [[100, 75, 130]]))
# These "asserts" are used for self-checking and not for an auto-testing
assert is_covered([200, 150], [[100, 75, 130]]) == True
assert is_covered([200, 150], [[50, 75, 100], [150, 75, 100]]) == True
assert is_covered([200, 150], [[50, 75, 100], [150, 25, 50], [150, 125, 50]]) == False
assert is_covered([200, 150], [[100, 75, 100], [0, 40, 60], [0, 110, 60], [200, 40, 60], [200, 110, 60]]) == True
assert is_covered([200, 150], [[100, 75, 100], [0, 40, 50], [0, 110, 50], [200, 40, 50], [200, 110, 50]]) == False
assert is_covered([200, 150], [[100, 75, 110], [105, 75, 110]]) == False
assert is_covered([200, 150], [[100, 75, 110], [105, 75, 20]]) == False
assert is_covered([3, 1], [[1, 0, 2], [2, 1, 2]]) == True
assert is_covered([30, 10], [[0, 10, 10], [10, 0, 10], [20, 10, 10], [30, 0, 10]]) == True
assert is_covered([30, 10], [[0, 10, 8], [10, 0, 7], [20, 10, 9], [30, 0, 10]]) == False
print("Coding complete? Click 'Check' to earn cool rewards!")
March 13, 2020
Comments: