I am trying to make a function which takes in 4 nested lists as input and returns a single conjoined nested list of the 4 input lists combined in a square shape. The first list would be the upper left corner, second list upper right, third bottom left, fourth bottom right. Note, the length of all 4 lists will always be the same. Also, the amount of elements in the inner lists will always equal the amount of inner lists.
For example, if the input is: list1=[[1,2], [3,4]], list2=[[2,1], [4,3]], list3=[[3,4], [1,2]], list4=[[4,3], [2,1]]
the output would be [[1,2,2,1], [3,4,4,3], [3,4,4,3], [1,2,2,1]] because it would be visualized as:
List1 List2
[1,2] [2,1]
[3,4] [4,3]
List3 List4
[3,4] [4,3]
[1,2] [2,1]
Right now, The pseudocode I have been able to come up with is as follows:
function combine(l1, l2, l3, l4):
list final = [];
for (int i = 0; i < (l1.length * 2; i++):
list new = [];
for (int j = 0; j < l1.length; j++):
new.append(i'th list[j]);
final.append(new);
return final;
I can't seem to figure out how to access the correct elements of the correct array to perform this because this function should perform correctly for any set of 2^n * 2^n arrays.
Any help would be greatly appreciated!