-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgenki.py
executable file
·69 lines (65 loc) · 1.43 KB
/
genki.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
#!/usr/bin/python
from math import log
import matplotlib.pyplot as plt
import matplotlib.patches as patches
import random
#Generador de puntos random
global enemigos
global T
global N
N=50
T=10
maximum = 10000
enemigos = [0 for x in range(N)]
maxX =maximum
minY = 1
fig1 = plt.gca()
for i in range(N):
x = random.randint(random.randint(maxX/(N-i),maxX),maxX)
y = random.randint(minY,random.randint(minY,maximum/(N-i) + minY))
enemigos[i] = (x,y)
maxX=x
minY=y
##esto era pra printearlo en un grafico, no darle bola
#ax1 = fig1.add_subplot(111, aspect='equal')
# fig1.add_patch(
# patches.Rectangle((0,0),
# enemigos[0][0],
# enemigos[0][1], # (x,y)
# #1, # width
# #1, # height
# facecolor="blue",
# )
#)
#testList2 = [(elem1, log(elem2)) for elem1, elem2 in enemigos]
#plt.scatter(*zip(*testList2))
#plt.show()
def mata(i,j):
global T
global enemigos
return ((enemigos[j][0] <= enemigos[i][0]+ T) & ((enemigos[j][1] ) <= enemigos[i][1]+T))
def si_la_tiro_aca_mueren(i):
global N
global T
global enemigos
#hasta cual mata
hasta=i
desde=i
while hasta<N and mata(i,hasta):
hasta= hasta+ 1
return (desde,hasta-1)
print "Enemigos:"
print enemigos
#i=1
sols = []
i=0
while i <N-1:
j=i
while ((j<N) and mata(j,i)):
j+=1
j-=1
mueren_con_j = si_la_tiro_aca_mueren(j)
sols.append(enemigos[j])
i=mueren_con_j[1]+1
print "soluciones: ",sols
print "#Soluciones: ",len(sols)