Finding index values based on coordinate

350 Views Asked by At

(0, 7) 1
(1, 7) 2
(2, 7) 3
(3, 7) 4
(4, 7) 5
(5, 7) 6
(6, 7) 7
(7, 7) 8
(0, 6) 9
(1, 6) 10
(2, 6) 11
(3, 6) 12
(4, 6) 13
(5, 6) 14
(6, 6) 15
(7, 6) 16
(0, 5) 17
(1, 5) 18
(2, 5) 19
(3, 5) 20
...

I have an incomplete list of coordinates here, each tied with an index number. This list of coordinate-index pairs goes up to 64, with the coordinates following the same pattern as we go down the list. I am trying to find a function that takes as input the coordinate values and output its respective index value. For example,
f(0, 7) = 1,
f(2, 6) = 11,
f(0, 5) = 17,
f(0, 4) = 25,
and so on. How can this be done?

1

There are 1 best solutions below

0
On

It's not difficult to guess that the expression is linear in this case. We can take $$ f(x,y) = ax+by+c $$ and plug in some numbers. First, we see that when $x$ increases by $1$, the result ($f$) also increases by $1$. Therefore $a=1$.

How about $b$ ? We see that when $y$ decreases by 1, the result increases by 8. Therefore, $b=-8$.

The constant $c$ can be solved by plugging in the first line, for example; $$ f(0,7) = 0-8 \cdot 7 + c = 1 \quad \Rightarrow c = 57 $$ Now the final expression is $$ f(x,y) = x-8y + 57 $$