day 17
trick shot
approach
a probe starts at the origin with some velocity; each step it moves, drag pulls its x velocity towards 0 and gravity lowers its y velocity by 1. the solution simply tries every velocity in a bounded range: vx from 0 to just past the target's far edge (anything faster overshoots on the first step), and vy from the target's bottom to its absolute value. each shot is simulated until it either hits the target or passes it.
part 1 keeps the highest point reached by any shot that hits. part 2 counts how many velocities hit at all.
the trick
the target bounds the search: a shot faster than the target is far can never land, so brute force over a small box is enough.
python
def possible_velocities(ts, te):
mny = min(te.y, ts.y)
for vx in range(te.x + 2):
for vy in range(mny, abs(mny)):
yield Point(vx, vy)