Expand an array to all directions by duplicating the outer elements
You will be given two inputs: an array and the expansion degree
For example if I give you [[1,2,3][4,5,6][7,8,9]]
and 3
,
you must output:
1 1 1 1 2 3 3 3 3
1 1 1 1 2 3 3 3 3
1 1 1 1 2 3 3 3 3
1 1 1 1 2 3 3 3 3
4 4 4 4 5 6 6 6 6
7 7 7 7 8 9 9 9 9
7 7 7 7 8 9 9 9 9
7 7 7 7 8 9 9 9 9
7 7 7 7 8 9 9 9 9
As you can see the given array is in the center and all the outer elements have expanded:
1
-> 3 times up, 3 times left and also to every position of the upper left corner
2
-> 3 times up
5
-> is not an outer element
etc
here are some more test cases to make things clearer
Input [[4,5,6]],0
Output
4 5 6
Input [[1]],2
Output
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
Input [[1,2,3]],2
Output
1 1 1 2 3 3 3
1 1 1 2 3 3 3
1 1 1 2 3 3 3
1 1 1 2 3 3 3
1 1 1 2 3 3 3
Input [[1,2,3][11,22,33][111,222,333][1111,2222,3333]],1
Output
1 1 2 3 3
1 1 2 3 3
11 11 22 33 33
111 111 222 333 333
1111 1111 2222 3333 3333
1111 1111 2222 3333 3333
You can use as many whitespaces as you like.
But the output has to be a mXn
array just like it is shown here.
You cannot output a list of lists.
This is codegolf Shortest answer on bytes wins