Evaluate Index of Multidimensional Coordinates A collection of N dimensional coordinates are provided. An example is below:

{2,3,4}


This can be thought of as a 3 dimensional array with 2x's, 3y's and 4z's; there may be any number of dimensions. In the example, there are 24 total nodes. Each node can be indexed using {x,y,z}. To access the 5th node, the provided indices would be {0, 1, 0} based on the table below.

## | x y z
     0 1 2
-----------
0  | 0 0 0
1  | 0 0 1
2  | 0 0 2
3  | 0 0 3
4  | 0 1 0
5  | 0 1 1
6  | 0 1 2
7  | 0 1 3
8  | 0 2 0
...
23 | 1 2 3


The purpose of this application is to work backwards to determine an index if given a node number.

If asked for the "y" index of the 8th node, the program should print "2".

With the following input provided:

{2,3,4}|8|1
&lt;List of Coordinates&gt;|&lt;Node&gt;|&lt;Index&gt;


The following should be printed:

2


You can assume that the input will be provided in some convenient manner in your language of choice and does not require bounds checking. For example you may assume that the provided index of choice ("y" in the example) is valid with respect to the provided coordinates. You may use 0 or 1 based indexing; the example presumes 0 based.

This is sort of the reverse of this question:
Index of a multidimensional array
MATL, 8 bytes

PiX[vPi)


This uses 1-based indexing for the node and for the dimensions. So the first nodes are 1, 2 etc; and the "x" dimension is 1, "y" is 2 etc.

Try it online!

Explanation

The key is to use function X[ (corresponding to ind2sub in Matlab or Octave), which converts a linear index into multidimensional indices. However, the order of dimensions if the opposite as defined in the challenge, so P (flip) is needed before calling the function, and again after concatenating (v) its ouputs.

P    % Implicit input: size as a row vector. Flip
i    % Input: node (linear) index
X[   % Convert from linear index to multidimensional indices. Produces
     % as many outputs as entries there are in the size vector
v    % Concatenate all outputs into a column vector
P    % Flip
i    % Input: dimension
)    % Index: select result for that dimension. Implicitly display