module Day17 where import Debug.Trace (trace) xmin = 111 xmax = 161 ymin = -154 ymax = -101 x_vel_to_pos :: Int -> Int x_vel_to_pos 0 = 0 x_vel_to_pos x = x + (x_vel_to_pos (x-1)) x_vel :: Int x_vel = head $ filter (\x -> let pos = x_vel_to_pos x in pos >= xmin && pos <= xmax) $ [0..] max_y :: Int -> Int max_y yv = go yv 0 where go vel pos = if vel <= 0 then pos else go (vel-1) (pos+vel) x_y_reaches :: Int -> Int -> Int -> Int -> Bool x_y_reaches xv yv x y | x >= xmin && x <= xmax && y >= ymin && y <= ymax = True | y < ymin || x > xmax = False | otherwise = x_y_reaches (max (xv-1) 0) (yv-1) (x+xv) (y+yv) try_y :: [Int] try_y = filter (\yv -> x_y_reaches x_vel yv 0 0) [0..250] try_x_y :: Int -> [Int] try_x_y xv = filter (\yv -> x_y_reaches xv yv 0 0) [-250..250] main :: IO () main = do print "bye"