Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Building Visibility solution in Uncategorized category for Building Visibility by capback250
# migrated from python 2.7
from collections import defaultdict
from random import randint
def checkio(coords):
visible = defaultdict(list)
projections = set()
maxH = max([x[2] for x in coords])
for x in range(maxH+1):
for building in coords:
if x in range(building[0], building[2]):
visible[x].append(building)
for i, j in list(visible.items()):
if len(j) == 1:
projections.add(str(j[0]))
else:
order = sorted(j, key=lambda x: x[1])
projections.add(str(order[0]))
for i in range(len(order) - 1):
if order[i][-1] < order[i+1][-1]:
projections.add(str(order[i+1]))
return len(projections)
Feb. 12, 2016