-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathd12a_bruteforce.py
61 lines (46 loc) · 1.63 KB
/
d12a_bruteforce.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
import re
import numpy as np
debug = 1
p = [[[] for i in range(3)] for i in range(4)]
v = [[[0] for i in range(3)] for i in range(4)]
pattern = re.compile('(?:=)(-?\d+)')
for i, line in enumerate(open('d12.txt')):
match = re.findall(pattern,line)
#x[i] = np.array([int(match[0]),int(match[1]),int(match[2])])
p[i][0] = int(match[0])
p[i][1] = int(match[1])
p[i][2] = int(match[2])
pos = np.array(p)
vel = np.zeros(pos.shape)
#pot = np.zeros(4)
#kin = np.zeros(4)
#total = np.zeros(4)
tmp = np.concatenate((pos,vel),axis=1)
hist = np.array([])
hist = np.append(hist,tmp.flatten())
print(hist)
#if debug==1: print(pos)
n = 10000000
for t in range(n):
for moon in range(4):
# x coords < current
vel[moon,0] = vel[moon,0] + len(np.where(pos[:,0] > pos[moon,0])[0]) - len(np.where(pos[:,0] < pos[moon,0])[0])
vel[moon,1] = vel[moon,1] + len(np.where(pos[:,1] > pos[moon,1])[0]) - len(np.where(pos[:,1] < pos[moon,1])[0])
vel[moon,2] = vel[moon,2] + len(np.where(pos[:,2] > pos[moon,2])[0]) - len(np.where(pos[:,2] < pos[moon,2])[0])
for moon in range(4):
pos[moon,0] = pos[moon,0] + vel[moon,0]
pos[moon,1] = pos[moon,1] + vel[moon,1]
pos[moon,2] = pos[moon,2] + vel[moon,2]
tmp = np.concatenate((pos,vel),axis=1)
tmp = tmp.flatten()
if t>0:
if any((hist[:]==tmp).all(1)):
print('Found match at t =',t+1)
break
hist = np.vstack((hist,tmp))
#pot[moon] = abs(pos[moon,0])+abs(pos[moon,1])+abs(pos[moon,2])
#kin[moon] = abs(vel[moon,0])+abs(vel[moon,1])+abs(vel[moon,2])
#total[moon] = pot[moon] * kin[moon]
#print('pot = ',pot[moon],' kin = ',kin[moon],' total = ',total[moon])
print(hist.shape)
print(hist)