aoc/2018/03/03.py
2021-05-14 03:53:06 -05:00

26 lines
553 B
Python

with open("input.txt") as f:
lines = f.read().splitlines()
import re
claims = [[*map(int, re.findall(r'\d+', line))] for line in lines]
from collections import Counter
fabric = Counter(
(i,j)
for id, x, y, width, height in claims
for i in range(x,x+width)
for j in range(y,y+height)
)
ans1 = sum(1 for c in fabric.values() if c > 1) # more than 1 claim
print("Part 1:",ans1)
ans2 = next(
id
for id, x, y, width, height in claims
if all(fabric[(i,j)] == 1
for i in range(x,x+width)
for j in range(y,y+height)
)
)
print("Part 2:",ans2)