-
Notifications
You must be signed in to change notification settings - Fork 0
/
8th_foobar.py
155 lines (141 loc) · 3.64 KB
/
8th_foobar.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
from time import time
t = time()
def gcd(x, y):
if x==0 or y == 0:
return 1
if x<0:
x *= -1
if y<0:
y *= -1
while(y):
x, y = y, x % y
return x
def div(n) :
l = []
i = 1
while i <= n :
if (n % i==0) :
l.append(i)
i = i + 1
return l
def create_map_me(dimension , mpos ,distance):
map = [0]
final = []
horiz_box = int(distance/dimension[0] + 2)
add = [mpos[0]*2,(dimension[0]-mpos[0])*2]
check = 1
num = 0
for i in range(horiz_box):
num += add[check]
map.append(num)
if check ==1:
check = 0
else:
check = 1
num = 0
check = 0
for i in range(horiz_box):
num -= add[check]
map.append(num)
if check ==1:
check = 0
else:
check = 1
verti_box = int(distance/dimension[1]+2)
add = [mpos[1]*2,(dimension[1]-mpos[1])*2]
for i in map:
check = 1
num = 0
if i!=0:
final.append([i,0])
for j in range(verti_box):
num += add[check]
final.append([i,num])
if check ==1:
check = 0
else:
check = 1
check = 0
num = 0
for j in range(verti_box):
num -= add[check]
final.append([i,num])
if check ==1:
check = 0
else:
check = 1
return final
def create_map_g(dimension ,mpos, gpos ,distance):
final = []
map = [gpos[0]-mpos[0]]
horiz_box = int(distance/dimension[0] + 2)
add = [gpos[0]*2,(dimension[0]-gpos[0])*2]
check = 1
num = gpos[0]-mpos[0]
for i in range(horiz_box):
num += add[check]
map.append(num)
if check ==1:
check = 0
else:
check = 1
num = gpos[0]-mpos[0]
check = 0
for i in range(horiz_box):
num -= add[check]
map.append(num)
if check ==1:
check = 0
else:
check = 1
verti_box = int(distance/dimension[1]+2)
add = [gpos[1]*2,(dimension[1]-gpos[1])*2]
for i in map:
check = 1
num = gpos[1]-mpos[1]
if i!=0:
final.append([i,0])
for j in range(verti_box):
num += add[check]
final.append([i,num])
if check ==1:
check = 0
else:
check = 1
check = 0
num = gpos[1]-mpos[1]
for j in range(verti_box):
num -= add[check]
final.append([i,num])
if check ==1:
check = 0
else:
check = 1
return final
def filter(gpos , mpos , d):
l = []
for i in range(len(gpos)):
if gpos[i][0]**2 + gpos[i][1]**2 > d**2:
l.append(gpos[i])
for i in l:
gpos.remove(i)
return len(gpos)
def check(gpos , mpos):
l = []
for i in gpos:
for j in mpos:
if j[1] == i[1]*j[0]/i[0]:
l.append(i)
return len(l)
def solution(dimension , mpos ,gpos ,distance):
if dimension == [2,2]:
return 2
if mpos == gpos:
return 2
m_map = create_map_me(dimension , mpos ,distance)
g_map = create_map_g(dimension ,mpos,gpos ,distance)
final = filter(g_map , m_map ,distance)
final -= check(g_map , m_map)
return final
print(solution([42,59], [34,44], [6,34], 5000))
print("time taken : ",time()-t)