10-12-2012 05:11 AM
I want to duplicate all the borders of my 2d array a few times so I get a coppy of all outside rows and cols next to them.
Example:
Original: 1 2 3 4
(4-4) 5 6 7 8
9 10 11 12
13 14 15 16
Output: 1 1 2 3 4 4
6-6 1 1 2 3 4 4
5 5 6 7 8 8
9 9 10 11 12 12
13 13 14 15 16 16
13 13 14 15 16 16
(In the middle of the output array you find the origingal array)
I need to get up to 6 kopies of the borders.
So 6 kopie col than the original array and again 6 kopie col.
Same for the rows.
(example has 1 kopie col than the original array and again 1 kopie col.)
Solved! Go to Solution.
10-12-2012 05:40 AM
Hi
A partial solution may be as shown below
10-12-2012 05:52 AM - edited 10-12-2012 05:52 AM
There are many ways obviously, this is slightly long winded. But will do the job.
10-12-2012 06:45 AM
Indeed this does the job as in the example.
But I have a 2d array whit random numers as input.
I don't know what the value of the element will be.
What makes it a lot more difficult...
It also can be this:
Original: 10 23 133 44
(4-4) 58 16 37 80
999 10 131 72
13 54 50 56
Output:
(6-6) 10 10 23 133 44 44
10 10 23 133 44 44
58 58 16 37 80 80
999 999 10 131 72 72
13 13 54 50 56 56
13 13 54 50 56 56
10-12-2012 06:47 AM
The code I posted will still work for random numbers.
10-12-2012 06:48 AM - edited 10-12-2012 06:50 AM
I'm thinking it looks like recursion, but I made this instead:
Note - the little For loops were the beginnings of a recursive solution that would work for 2D and 1D arrays. I had Matrix and Array size and decrement primitives.
10-12-2012 07:41 AM
Thanks for you help guy (.aCe.,jcarmody )!
Both solutions work out!
10-12-2012 07:45 AM
@koekie wrote:
[...]
I need to get up to 6 kopies of the borders.
So 6 kopie col than the original array and again 6 kopie col.Same for the rows.
(example has 1 kopie col than the original array and again 1 kopie col.)
Is this what you're looking for?
10-12-2012 08:30 AM
Yes indeed, that was what I need! 🙂
10-14-2012 05:50 AM