Bouncing in an array
Pyth, 17 bytes
>lQC.e.>bkC+_PtQQ
Explanation:
implicit: Q=input
> First
l Q len(Q) elements of the
C .e Transpose of enumerated map lambda b,k:
.> Rotate the kth element rightwards by
b
k k.
C + Transpose of: Q concatenated to
_ P t Q itself reversed without first and last elements.
Q
Try it here.
JavaScript (ES6), 70
a=>a.map((r,k)=>r.map((e,j)=>(a[k-=d]||a[d=-d,k-=d+d]||r)[j],d=1,++k))
TEST
F = a=>a.map((r,k)=>r.map((e,j)=>(a[k-=d]||a[d=-d,k-=d+d]||r)[j],d=1,++k))
test = [{
I: [
[1, 2, 3, 4, 5],
[6, 7, 8, 9, 0]
],
O: [
[1, 7, 3, 9, 5],
[6, 2, 8, 4, 0]
]
}, {
I: [
[1, 2, 3, 4, 5]
],
O: [
[1, 2, 3, 4, 5]
]
}, {
I: [
[0, 0, 0, 0, 0, 0, 0, 0],
[9, 9, 9, 9, 9, 9, 9, 100],
[0, 0, 0, 0, 0, 0, 0, 0]
],
O: [
[0, 9, 0, 9, 0, 9, 0, 100],
[9, 0, 9, 0, 9, 0, 9, 0],
[0, 9, 0, 9, 0, 9, 0, 100]
]
}, {
I: [
[0, 1, 2, 3, 4, 5],
[6, 7, 8, 9, 10, 11],
[12, 13, 14, 15, 16, 17]
],
O: [
[0, 7, 14, 9, 4, 11],
[6, 1, 8, 15, 10, 5],
[12, 7, 2, 9, 16, 11]
]
}, {
I: [
[0, 0, 0, 0, 0, 0],
[1, 2, 3, 4, 5, 6],
[2, 2, 2, 2, 2, 2],
[9, 8, 7, 6, 5, 4]
],
O: [
[0, 2, 2, 6, 2, 6],
[1, 0, 3, 2, 5, 2],
[2, 2, 0, 4, 2, 4],
[9, 2, 3, 0, 5, 2]
]
}];
console.log = x => O.textContent += x + '\n';
test.forEach(t => {
var r = F(t.I),
ok = r.join `\n` == t.O.join `\n`
console.log((ok ? 'OK' : 'KO') + '\nInput\n' + t.I.join `\n` + '\nOutput\n' + r.join `\n` + '\n')
})
<pre id=O></pre>
CJam, 31 30 bytes
q~__W%1>W<+_z,_@*<zee::m>z\,<p
Input and output as a list of CJam-style arrays.
Test it here.
Most definitely golfable...