Advertisement
Guest User

advent2018 day3

a guest
Dec 2nd, 2018
143
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import sys
  2. import re
  3.  
  4. RE_CLAIM = re.compile(r'#(\d+)\s@d+),(\d+):\s(\d+)x(\d+)')
  5. i_ = [i for i in sys.stdin.read().strip().split('\n')]
  6. FABRIC = [[set() for j in range(1000)] for i in range(1000)]
  7. a = set()
  8.  
  9. for i in i_:
  10.     m = RE_CLAIM.match(i)
  11.     a.add(m.group(1))
  12.     o_l = int(m.group(2))
  13.     o_t = int(m.group(3))
  14.     w = int(m.group(4))
  15.     h = int(m.group(5))
  16.     for j in range(h):
  17.         for k in range(w):
  18.             FABRIC[j + o_t][k + o_l].add(m.group(1))
  19.  
  20. overlap = 0
  21. bad = set()
  22. for row in FABRIC:
  23.     for col in row:
  24.         if len(col) > 1:
  25.             overlap += 1
  26.             bad |= col
  27.  
  28. print('part1:', overlap)
  29. print('part2:', ''.join(a - bad))
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement