massung
2021-12-17 08:50:54

Did it with mostly brute force as well.

Broke it up into brute force in the x-range to find all valid velocities and the valid time steps for which (in the x coordinate) it would be in the target area.

Then used those time stamps to limit the scope of the y-velocities.

Still brute force tested y, but I really wanted to just use s=vt+a(t^2)/2 to calculate v for the valid y + x time spans. But I wasn’t getting it to work out. So, I’ll revisit in the morning.


ben.knoble
2021-12-17 19:01:18

My notes may interest folks, but my soln for part2 involved expanding some bounds until I got it right :/ https://github.com/benknoble/advent2021/blob/main/day17/solution.rkt


badkins
2021-12-17 19:40:50

<https://github.com/lojic/LearningRacket/blob/master/advent-of-code–2021/solutions/day17/day17.rkt|Day 17>



massung
2021-12-17 21:04:24

I tried something a little different this afternoon. I traverse the Y direction and build a hash table of “time step -> list of initial VY’s that end up in the target area at that time step”.


massung
2021-12-17 21:05:01

Then traverse in X, and for every time step where X is in the range, pair up with all the VYs for that time step from the hash table.


massung
2021-12-17 21:06:31

Optimizations aside from the hash table include are mostly about recognizing that going up can be ignored. Only go down and - for going up - realize that for some initial VY, you’ll be back at y=0 again at step vy*2+1 with vy=-vy-1, so a whole lot of loop iterating can be skipped.


massung
2021-12-17 21:07:20

I still think this could be a simple physics problem, but I couldn’t rectify vx eventually stopping in the equations.


badkins
2021-12-17 22:24:07

(require plot) (define (plot-trajectory dx dy) (let ([ pts (trajectory dx dy) ]) (plot (list (rectangles (list (vector (ivl 206 250) (ivl -57 -105)))) (points pts)) #:x-min -1 #:x-max 300 #:y-min -150 #:y-max 100))) (plot-trajectory 21 12)


badkins
2021-12-17 22:27:34

I love how I can just hit <F5> in Emacs, and see the plot in the repl window!