I have a 4x4 grid stored as a one-dimensional array, each cell can contain a random number:
var g1 = [
1, 0, 0, 0,
0, 2, 0, 0,
0, 0, 0, 3,
0, 0, 1, 0
];
How can I increase the resolution of that grid to get this 8x8 grid as an array:
var g2 = [
1, 1, 0, 0, 0, 0, 0, 0,
1, 1, 0, 0, 0, 0, 0, 0,
0, 0, 2, 2, 0, 0, 0, 0,
0, 0, 2, 2, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 3, 3,
0, 0, 0, 0, 0, 0, 3, 3,
0, 0, 0, 0, 1, 1, 0, 0,
0, 0, 0, 0, 1, 1, 0, 0
];
The source array will be of different sizes, but the increase in resolution (1 to 4) will be the same. What's the most efficient way to calculate the indices of the new array?
Similar to this question, but not quite the same since this is a one-dimensional array and not python specific. I'm looking for a calculation. Thanks!