I think I know what you're trying to say here, so here's an attempt at solving this (if I'm way off let me know, your description is a little vague):

Well you could use a 2-dimensional array, representing your grid, then use your -1/0/+1 as a change in the indexes, but that's more than you really need.

Look at it this way, what changes do those numbers really result in? The first moves you left or right, no matter where you are, the results in adding the same to the number (e.g. you start at 4, the first number is +1, you move to 5, which is 4 + 1). So just add the first number to 4. The second number moves you up or down. These all result in a change of 3*[second number] (e.g. you;re at 3, the second number is -1, you add -1*3 to 3 and get: 3 + (-1 * 3) = 0).

So the simplest way is:

4 + [first number] + [second number] * 3

15,312,353 members