Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Rectangles Union by Moff
def rectangles_union(recs):
result = 0
if recs:
minx, miny = (min(r[i] for r in recs) for i in (0, 1))
maxx, maxy = (max(r[i] for r in recs) for i in (2, 3))
for x in range(minx, maxx + 1):
for y in range(miny, maxy + 1):
for x1, y1, x2, y2 in recs:
if x1 <= x < x2 and y1 <= y < y2:
result += 1
break
return result
Oct. 22, 2018