Skip to content

Commit eb6b690

Browse files
committed
Day 17, Part 2
1 parent 02b6a4c commit eb6b690

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

day_17/__main__.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,23 +58,28 @@ def simulate(self, probe_velocity: Point):
5858
velocity = probe_velocity
5959
max_height = self.probe_loc.y
6060

61-
while not self.in_trench() and self.probe_loc.x <= max(self.trench_from.x,self.trench_to.x) and self.probe_loc.y >= max(self.trench_from.y,self.trench_to.y):
61+
while not self.in_trench() and self.probe_loc.x <= self.trench_to.x and self.probe_loc.y >= self.trench_from.y:
6262
self.probe_loc = Point(x=self.probe_loc.x + velocity.x, y=self.probe_loc.y + velocity.y)
6363
max_height = max(max_height, self.probe_loc.y)
6464
velocity = Point(x=Everything._drag(velocity.x), y=velocity.y-1)
6565
# print(self)
66-
# print(velocity)
66+
# print(velocity, self.probe_loc, self.trench_from, self.trench_to)
67+
# print(self.in_trench())
6768

6869
return self.in_trench(), max_height
6970

7071
ev = Everything.read_input(sys.stdin)
71-
# hit, max_height = ev.simulate(probe_velocity=Point(x=6,y=3))
72+
# hit, max_height = ev.simulate(probe_velocity=Point(x=6,y=0))
7273
# print(hit, max_height)
7374

74-
max_hit=0
75-
for x in range(-2*abs(ev.trench_to.x), 2*abs(ev.trench_to.x)):
76-
for y in range(-2*abs(ev.trench_to.y), 2*abs(ev.trench_to.y)):
77-
hit, max_height = ev.simulate(probe_velocity=Point(x=x,y=y))
75+
hits = set()
76+
for x in range(0, 4*abs(ev.trench_to.x)):
77+
for y in range(-4*abs(ev.trench_to.y), 4*abs(ev.trench_to.y)):
78+
velocity = Point(x=x,y=y)
79+
hit, max_height = ev.simulate(probe_velocity=velocity)
7880
if hit:
79-
max_hit=max(max_hit, max_height)
80-
print(max_hit)
81+
hits.add(velocity)
82+
# for hit in sorted(list(hits)):
83+
# print(hit)
84+
print(len(hits))
85+
# print(len(hits), hits)

0 commit comments

Comments
 (0)