import numpy import re RE = re.compile(r"#(\d+) @ (\d+),(\d+): (\d+)x(\d+)") with open("Day3.in", "r") as f: ROWS = [[int(i) for i in RE.match(line).groups()] for line in f] FABRIC = numpy.zeros((1000, 1000), dtype=numpy.uint8) for _, x, y, w, h in ROWS: FABRIC[x:x+w, y:y+h] += 1 for i, x, y, w, h in ROWS: if (FABRIC[x:x+w, y:y+h] == 1).all(): print(i) break