-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path05a.py
More file actions
executable file
·35 lines (26 loc) · 737 Bytes
/
05a.py
File metadata and controls
executable file
·35 lines (26 loc) · 737 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env python3
import numpy as np
import re
def render(board, l):
if l[0] == l[2]:
a = l[1]
b = l[3]
if a > b:
b, a = a, b
board[a:b+1, l[0]] += 1
elif l[1] == l[3]:
a = l[0]
b = l[2]
if a > b:
b, a = a, b
board[l[1], a:b+1] += 1
return board
with open('05.input', 'r') as f:
lines = [[int(c) for c in g] for g in re.findall('(\d+),(\d+)\s->\s(\d+),(\d+)', f.read())]
lines = list(filter(lambda l: l[0] == l[2] or l[1] == l[3], lines))
m = np.max(np.array(lines)) + 1
board = np.zeros((m,m))
for line in lines:
board = render(board, line)
result = np.sum(board >= 2)
print(result)