Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
1-liner solution in Clear category for Rectangles Union by Merzix
from typing import List, Tuple
def rectangles_union(recs: List[Tuple[int]]) -> int:
return len({(i,j) for x0, y0, x1, y1 in recs
for i in range(x0, x1)
for j in range(y0, y1)})
if __name__ == '__main__':
assert rectangles_union([
(6, 3, 8, 10),
(4, 8, 11, 10),
(16, 8, 19, 11)
]) == 33
assert rectangles_union([
(16, 8, 19, 11)
]) == 9
assert rectangles_union([
(16, 8, 19, 11),
(16, 8, 19, 11)
]) == 9
assert rectangles_union([
(16, 8, 16, 8)
]) == 0
assert rectangles_union([
]) == 0
Oct. 17, 2018