-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10a.py
75 lines (61 loc) · 1.52 KB
/
10a.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
file_name = "10a.txt"
import numpy as np
np.set_printoptions(threshold=np.nan)
import re
def preprocess(x):
pre = re.compile(r'(?<=position=<).*(?=> v)')
vre = re.compile(r'(?<=velocity=<).*(?=>)')
records = []
for r in x:
pm = pre.findall(r)
vm = vre.findall(r)
p = [ int(i.strip()) for i in pm[0].split(',')]
v = [ int(i.strip()) for i in vm[0].split(',')]
rd = {"p": p, "v": v}
records.append( rd )
return records
def render(x):
px = [i['p'][0] for i in x]
py = [i['p'][1] for i in x]
print( 'x positions->', min(px), max(px), ' range ', max(px) - min(px))
print( 'y positions->', min(py), max(py), ' range ', max(py) - min(py))
xr = max(px) - min(px)
yr = max(px) - min(px)
charar = np.chararray((yr+1, xr+1))
for r in x:
xx,yy = r['p']
charar.itemset((yy-179,xx-190), b'#')
check = charar.count(b'#')
print( check)
def stats(x):
px = [i['p'][0] for i in x]
py = [i['p'][1] for i in x]
xmode = max(px, key=lambda l: px.count(l))
ymode = max(py, key=lambda l: py.count(l))
return px.count(xmode) * py.count(ymode)
def step(x):
modemax = 0
modemaxindex = 0
count=0
while count <= 10866:
for r in x:
r['p'][0] += r['v'][0]
r['p'][1] += r['v'][1]
# m = stats(x)
# if m > modemax:
# modemax = m
# modemaxindex = count
if count == 10866:
render(x)
break
count += 1
#print( 'modemax ', modemax )
#print( 'modemaxindex ', modemaxindex )
return
def main():
with open(file_name, 'r') as f:
x = f.readlines()
print(len(x))
x = preprocess(x)
step(x)
main()