I need to choose an aray item based on the values of 4 variables, as shown below, in C.
0 | 1 | 0 | -1 | array[1][0]
-1 | 0 | 1 | 0 | array[1][1]
0 | -1 | 0 | 1 | array[1][2]
1 | 0 | -1 | 0 | array[1][3]
1 | 0 | 0 | -1 | array[2][0]
1 | 0 | 0 | 1 | array[2][1]
-1 | 0 | 0 | 1 | array[2][2]
-1 | 0 | 0 | -1 | array[2][3]
0 | 1 | -1 | 0 | array[3][0]
0 | 1 | 1 | 0 | array[3][1]
0 | -1 | 1 | 0 | array[3][2]
0 | -1 | -1 | 0 | array[3][3]
(The order of the second column in the array isn't important and can be reordered if needed.)
While it's possible (and completely acceptable) to just stick all the possibilities in 12 chained if
s, I'd like to see if anyone can come up with a "cleaner" solution.
EDIT: to clarify: I want a function f(a,b,c,d)
where (for example) f(0, 1, 0, -1)
returns the value held in array[1][0]
.