Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
12-liner: view solution in Clear category for Building Visibility by przemyslaw.daniel
def checkio(buildings):
def visible_from_point(x_pos, blds, ret=[], height=0):
for i in sorted(blds, key=lambda x: x[1]):
if i[0] <= x_pos <= i[2] and i[4] > height:
ret, height = ret+[i], i[4]
return ret
a = [(x[0], x[2]) for x in buildings]
a = sorted(set([x for y in a for x in y]))
a = [(x[0]+x[1])/2 for x in zip(a, a[1:])]
a = __import__('functools').reduce(lambda x, y: x+y,
[visible_from_point(x, buildings) for x in a])
return len(set([str(x) for x in a]))
April 16, 2017
Comments: