parent
28d3677a68
commit
1a5d5866fd
|
@ -0,0 +1,21 @@
|
|||
#!/usr/bin/env python3
|
||||
import fileinput
|
||||
import re
|
||||
import numpy as np
|
||||
from collections import namedtuple
|
||||
|
||||
Claim = namedtuple('Claim', 'id, x, y, w, h')
|
||||
|
||||
|
||||
def main():
|
||||
fabric = np.zeros((1000, 1000))
|
||||
regex = re.compile(r'^\s*#(\d+)\s+@\s+(\d+),(\d+)[:\s]+(\d+)x(\d+)\s*$')
|
||||
claims = list(map(lambda x: Claim(*map(int, x)), map(next, map(iter, map(regex.findall, map(str.strip, fileinput.input()))))))
|
||||
for claim in claims:
|
||||
fabric[claim.x:claim.x+claim.w, claim.y:claim.y+claim.h] += 1
|
||||
lonely = next(filter(lambda c: not np.sum(fabric[c.x:c.x+c.w, c.y:c.y+c.h] > 1), claims))
|
||||
return np.sum(fabric > 1), lonely.id
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
print(main())
|
|
@ -0,0 +1 @@
|
|||
numpy>=1.15
|
Loading…
Reference in New Issue