input: -2, 1, 4 Output: 12, 9, 6
There could be be two line segments here. See
if the slope is the same for both.
Between points 1 and 2
m = (y2 - y1) / (x2 - x1)
m = (9 - 12) / (1 - (-2)
m = -3 / 3
m = -1
Between points 2 and 3
m = (6 - 9) / (4 - 1)
m = -3 / 3
m = -1
Let's try the slope between point 1 and point 3
m = (6 - 12) / (4 - (-2))
m = -6 / 6
m = -1
All of the slopes are the same. All we
need is a y-intercept, b.
b = y - mx
b = 12 - (-1)(-2)
b = 12 - 2
b = 10
The equation is:
y = -1x + 10
y = -x + 10