Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
proper for...else solution in Clear category for Four To The Floor by ssk8
from math import sqrt
from dataclasses import dataclass
@dataclass
class Point:
x: float
y: float
def distance(self, other):
return sqrt((self.x-other.x)**2+(self.y-other.y)**2)
@dataclass
class Sensor:
pos: Point
radius: int
def covered(self, other):
return self.pos.distance(other) <= self.radius
def is_covered(room, sensors):
sample_space = (Point(x+.9, y+.9) for x in range(room[0]) for y in range(room[1]))
sensors = [Sensor(Point(x,y), r) for x,y,r in sensors]
for sample in sample_space:
for sensor in sensors:
if sensor.covered(sample):
break
else: return False
return True
Dec. 30, 2021