Copyright | (c) Eric Mertens 2021 |
---|---|
License | ISC |
Maintainer | emertens@gmail.com |
Safe Haskell | None |
Language | Haskell2010 |
Main
Description
https://adventofcode.com/2021/day/17
Launch probes to hit a target.
This solution relies on the target being in quadrant IV. You could do the math for the other quadrants, but I didn't bother!
Boundary conditions:
- x velocity must be non-negative to hit things in quadrant IV
- x velocity must not be more than
xhi
or the probe will miss on the first timestep. - y velocity can't be more than
ylo
or it will miss on the first time step. - y velocity can't be more than
-ylo
or it will skip right past the target on its way back down.
Documentation
The state of a traveling probe
Arguments
:: Int | target x lo |
-> Int | target x hi |
-> Int | target y lo |
-> Int | target y hi |
-> Int | initial x velocity |
-> Int | initial y velocity |
-> Maybe Int | maximum height if successful |
Run a simulation returning the maximum height seen if the probe ever succeeds in hitting the target.
>>>
sim 20 30 (-10) (-5) 6 9
Just 45