Skip to content

Instantly share code, notes, and snippets.

@eltrufas
Created December 3, 2018 05:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eltrufas/b483b04e0eaebb39685b38a8b3b31fe4 to your computer and use it in GitHub Desktop.
Save eltrufas/b483b04e0eaebb39685b38a8b3b31fe4 to your computer and use it in GitHub Desktop.
advent of code day 3
import sys
lines = list(sys.stdin)
ss = [l.split(" ") for l in lines]
rects = []
for s in ss:
print(s)
x, y = s[2][:-1].split(',')
w, h = s[3].split('x')
x = int(x)
y = int(y)
w = int(w)
h = int(h)
x2, y2 = x + w, y + h
rects.append((x, y, x2, y2))
cloth = [[0 for _ in range(1000)] for _ in range(1000)]
for r in rects:
x, y, x1, y1 = r
for i in range(x, x1):
for j in range(y, y1):
cloth[i][j] += 1
filt = [c for r in cloth for c in r if c > 1]
print(len(filt))
ids = [s[0] for s in ss]
for idx, r in enumerate(rects):
x, y, x1, y1 = r
clean = True
for i in range(x, x1):
for j in range(y, y1):
if cloth[i][j] > 1:
clean = False
if clean:
print(ids[idx])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment