From c37eba39d1646244b66ad94c1b31dc03ce562103 Mon Sep 17 00:00:00 2001 From: Luna Lailatova Date: Wed, 29 Dec 2021 05:13:44 +0100 Subject: [PATCH] day 17 --- day17-2.py | 38 ++++++++++++++++++++++++++++++++++++++ day17.py | 7 +++++++ 2 files changed, 45 insertions(+) create mode 100644 day17-2.py create mode 100644 day17.py diff --git a/day17-2.py b/day17-2.py new file mode 100644 index 0000000..d25c0f5 --- /dev/null +++ b/day17-2.py @@ -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)) \ No newline at end of file diff --git a/day17.py b/day17.py new file mode 100644 index 0000000..ee55591 --- /dev/null +++ b/day17.py @@ -0,0 +1,7 @@ +targetx = (175, 227) +targety = (-134, -79) + +y = 0 - targety[0] - 1 +y = (y*y + y)/2 + +print(y) \ No newline at end of file