-
Notifications
You must be signed in to change notification settings - Fork 0
/
6b.py
52 lines (39 loc) · 908 Bytes
/
6b.py
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import numpy as np
file_name = "6a.txt"
def within10000(r,c,coords ):
d = 0
for pair in coords:
xdist = abs(pair[0] - c)
ydist = abs(pair[1] - r)
d += xdist
d += ydist
if d < 10000:
return True
else:
return False
def process(x):
coords = []
for c in x:
c = c.replace('\n','')
c = c.split(',')
x,y = int(c[0]), int(c[1].replace(' ',''))
coords.append( [x,y] )
minx = min([i[0] for i in coords])
miny = min([i[1] for i in coords])
maxx = max([i[0] for i in coords])
maxy = max([i[1] for i in coords])
base_arr = np.zeros(( maxy, maxx ))
for r in range(maxy):
for c in range(maxx):
within = within10000(r,c,coords)
if within:
base_arr.itemset((r,c), 1)
area = np.count_nonzero(base_arr == 1 )
print("max finite area ", area)
return
def main():
with open(file_name, 'r') as f:
x = f.readlines()
print(len(x))
process(x)
main()