Browse Source

day 17

main
Luna Lailatova 2 years ago
parent
commit
c37eba39d1
  1. 38
      day17-2.py
  2. 7
      day17.py

38
day17-2.py

@ -0,0 +1,38 @@ @@ -0,0 +1,38 @@
targetx = (175, 227) #(20, 30)
targety = (-134, -79) #(-10, -5)
trajectories = []
class probe:
def __init__(self, velo):
self.probe_position = (0, 0)
self.velocity = velo
self.initial_velo = velo
def steppy(self):
while self.probe_position[0] < targetx[1] and self.probe_position[1] > targety[0]:
x, y = self.probe_position
velox, veloy = self.velocity
x += velox
y += veloy
if x >= targetx[0] and x <= targetx[1] and y <= targety[1] and y >= targety[0]:
return self.initial_velo
veloy -= 1
if velox != 0:
if velox < 0:
velox += 1
if velox > 0:
velox -= 1
self.probe_position = (x, y)
self.velocity = (velox, veloy)
return None
for yvelo in range(targety[0], 0 - targety[0]):
for xvelo in range(1, targetx[1] + 1):
prob = probe((xvelo, yvelo))
t = prob.steppy()
if t is not None:
trajectories.append(t)
del prob
print(len(trajectories))

7
day17.py

@ -0,0 +1,7 @@ @@ -0,0 +1,7 @@
targetx = (175, 227)
targety = (-134, -79)
y = 0 - targety[0] - 1
y = (y*y + y)/2
print(y)
Loading…
Cancel
Save