myfabric = [[0 for n in range(1000)] for p in range(1000)]
myfabric[3][5]
0
with open('day3.txt') as f:
mydata = f.read().splitlines()
len(mydata)
1399
mydata[0]
'#1 @ 669,271: 17x11'
import re
mydata[0].split(['@',',',':','x'])
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-12-6f0ef5fa70bf> in <module>() ----> 1 mydata[0].split(['@',',',':','x']) TypeError: must be str or None, not list
re.split('@ |,|: |x', mydata[0])
['#1 ', '669', '271', '17', '11']
nums = [int(n) for n in re.split('@ |,|: |x', mydata[0])[1:]]
nums
[669, 271, 17, 11]
nums = [[int(n) for n in re.split('@ |,|: |x', elf)[1:]] for elf in mydata]
nums[:4]
[[669, 271, 17, 11], [153, 186, 20, 26], [186, 838, 28, 11], [119, 248, 18, 13]]
nums[-5:]
[[727, 567, 17, 25], [52, 176, 19, 21], [453, 308, 19, 24], [238, 370, 21, 18], [724, 519, 23, 10]]
import numpy as np
# fabric array
a = np.zeros(shape=(1000,1000))
x,y,xd,yd = nums[0]
x,y,xd,yd
(669, 271, 17, 11)
for e in nums:
x,y,xd,yd = e
a[y:y+yd,x:x+xd] += 1
(a > 1).sum()
118223
a[0,0],a[3,3],
--------------------------------------------------------------------------- IndexError Traceback (most recent call last) <ipython-input-12-06bee79ecdd3> in <module>() ----> 1 a[0,0],a[3,3],a[1000,1000] IndexError: index 1000 is out of bounds for axis 0 with size 1000
b = np.zeros(shape=(10,10))
b
array([[0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], [0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], [0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], [0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], [0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], [0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], [0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], [0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], [0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], [0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]])
b[3:7,1:5] += 1
b
array([[0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], [0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], [0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], [0., 1., 1., 1., 1., 0., 0., 0., 0., 0.], [0., 1., 1., 1., 1., 0., 0., 0., 0., 0.], [0., 1., 1., 1., 1., 0., 0., 0., 0., 0.], [0., 1., 1., 1., 1., 0., 0., 0., 0., 0.], [0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], [0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], [0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]])
b[1:5,3:7] += 1
b
array([[0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], [0., 0., 0., 1., 1., 1., 1., 0., 0., 0.], [0., 0., 0., 1., 1., 1., 1., 0., 0., 0.], [0., 1., 1., 2., 2., 1., 1., 0., 0., 0.], [0., 1., 1., 2., 2., 1., 1., 0., 0., 0.], [0., 1., 1., 1., 1., 0., 0., 0., 0., 0.], [0., 1., 1., 1., 1., 0., 0., 0., 0., 0.], [0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], [0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], [0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]])
b[5:7,5:7] += 1
b
array([[0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], [0., 0., 0., 1., 1., 1., 1., 0., 0., 0.], [0., 0., 0., 1., 1., 1., 1., 0., 0., 0.], [0., 1., 1., 2., 2., 1., 1., 0., 0., 0.], [0., 1., 1., 2., 2., 1., 1., 0., 0., 0.], [0., 1., 1., 1., 1., 1., 1., 0., 0., 0.], [0., 1., 1., 1., 1., 1., 1., 0., 0., 0.], [0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], [0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], [0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]])
(b > 1).sum()
4
--- Part Two ---
Amidst the chaos, you notice that exactly one claim doesn't overlap by even a single square inch of fabric with any other claim. If you can somehow draw attention to it, maybe the Elves will be able to make Santa's suit after all!
For example, in the claims above, only claim 3 is intact after all claims are made.
What is the ID of the only claim that doesn't overlap?