Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Building Visibility by ssk8
from dataclasses import dataclass
@dataclass
class Building:
x_sw: int
y: int
x_ne: int
_: int
height: float
id: int
def checkio(buildings):
buildings = [Building(*b, i) for i, b in enumerate(buildings)]
visible = set()
for cur_x in (n/2 for n in range(2*max(b.x_ne for b in buildings))):
highest = 0
for building in sorted((b for b in buildings if b.x_sw <= cur_x <= b.x_ne), key=lambda b: b.y):
if building.height > highest:
highest = building.height
visible.add(building.id)
return len(visible)
Dec. 29, 2021