Day17
Copyright(c) Eric Mertens 2021
LicenseISC
Maintaineremertens@gmail.com
Safe HaskellNone
LanguageHaskell2010

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.
Synopsis

Documentation

data Probe Source #

The state of a traveling probe

Constructors

P !Int !Int !Int !Int

x-position y-position x-velocity y-velocity

step :: Probe -> Probe Source #

Advance the probe one timestep

main :: IO () Source #

>>> :main
10585
5247

sim Source #

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