Function advent_of_code_2021::day_17::highest_point[−][src]

fn highest_point(target: ((isize, isize), (isize, isize))) -> isize
Expand description

The delta on the y-axis of -1 is such that the y co-ordinates of the points on the downward portion of the trajectory are the same as the upward portion, so there will be a co-ordinate on the x-axis for each trajectory that starts upwards. Further the trajectory(ies) with the highest peak will be travelling fastest at that point. As the target area is below the origin, The fastest possible trajectory at that point will be the x-axis followed by the lowest altitude of the target area (y_min). As the delta is -1 the height of the peak is a triangular number (n * (n + 1) / 2), where n is the distance of that final step 0..y_min. This is the distance between the peak and y_min. To get the height above the origin, we need to go back one step ((n-1) * ((n-1) + 1) / 2), simplified and with -y_min substituted for n: (-y_min - 1) * -y_min / 2.