Explanation:
in general, a linear function is always of the structure
y = ax + b
"a" is the slope of the line and is the ratio (y coordinate difference / x coordinate difference) when going from one point on the line to another.
"b" is the y-intercept (the y-value when x = 0).
so, if we don't see the solution right away with experience, we have to use the data points (usually starting with the first 2) to solve them 2 equations with 2 variables a, b :
2 = a×1 + b = a + b
1 = a×2 + b = 2a + b
now we can simply subtract the first equation from the second and get
1 = 2a + b
- 2 = a + b
------------------
-1 = a + 0
a = -1
1 = 2×-1 + b = -2 + b
b = 3
and the equation is
y = -x + 3
therefore, when the input is n (that means f(n))
y = output = -n + 3