Advertisement
Dojnaz

AoC Day3

Dec 17th, 2018
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.73 KB | None | 0 0
  1. import numpy as np
  2. import time
  3.  
  4. #Läs och rengör input
  5. def gen():
  6.     grid = np.zeros((1000, 1000))
  7.     vals = []
  8.     with open("input.txt", "r") as input:
  9.         for row in input.readlines():
  10.             id, sep, start, size = row.split()
  11.             x1, y1 = map(int, start[:-1].split(","))
  12.             x2, y2 = map(int, size.split("x"))
  13.             grid[x1:x1 + x2, y1:y1 + y2] += 1
  14.             vals.append((id, (x1, y1), (x2, y2)))
  15.     return grid, vals
  16.  
  17. #Del 1
  18. def p1():
  19.     grid, _ = gen()
  20.     return (grid >= 2).sum()
  21.  
  22. #Del 2
  23. def p2():
  24.     grid, vals = gen()
  25.     for id, (x1, y1), (x2, y2) in vals:
  26.         if (grid[x1:x1 + x2, y1:y1 + y2] == 1).all():
  27.             return id
  28.     return None
  29. print(p1())
  30. print(p2())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement