[Question]
  [
### Introduction
Arrays can also be seen as a field for a bouncing ball. This of course sounds very vague, so here is an example of an input:
```
[1, 2, 3, 4, 5, 6, 7, 8, 9]
[9, 8, 7, 6, 5, 4, 3, 2, 1]
[1, 2, 3, 4, 5, 6, 7, 8, 9]
```
The challenge is to output the **bounced arrays**. These are made from diagonal patterns which bounce at the edges of the field. This path is pointed *upwards*. The path for the first bounced array (in which the path is directly bounced off the egde), is:
```
[1, -, -, -, 5, -, -, -, 9]
[-, 8, -, 6, -, 4, -, 2, -]
[-, -, 3, -, -, -, 7, -, -]
```
From left to right, this would result in `[1, 8, 3, 6, 5, 4, 7, 2, 9]`. This is our *first* bounced array. The path for the second bounced array:
```
[-, 2, -, -, -, 6, -, -, -]
[9, -, 7, -, 5, -, 3, -, 1]
[-, -, -, 4, -, -, -, 8, -]
```
This results in `[9, 2, 7, 4, 5, 6, 3, 8, 1]`. The path for the third bounced array is:
```
[-, -, 3, -, -, -, 7, -, -]
[-, 8, -, 6, -, 4, -, 2, -]
[1, -, -, -, 5, -, -, -, 9]
```
This results in `[1, 8, 3, 6, 5, 4, 7, 2, 9]`. So the three *bounced arrays* are:
```
[1, 8, 3, 6, 5, 4, 7, 2, 9]
[9, 2, 7, 4, 5, 6, 3, 8, 1]
[1, 8, 3, 6, 5, 4, 7, 2, 9]
```
### Task
Given at least 1 array containing only non-negative integers, with all the arrays having the same length, output all the bounced arrays.
### Test cases
Test case 1:
```
Input:                       Output:
[1, 2, 3, 4, 5]              [1, 7, 3, 9, 5]
[6, 7, 8, 9, 0]              [6, 2, 8, 4, 0]
Input:                       Output:
[1, 2, 3, 4, 5]              [1, 2, 3, 4, 5]
Input:                       Output:
[0, 0, 0, 0, 0, 0, 0, 0]     [0, 9, 0, 9, 0, 9, 0, 100]
[9, 9, 9, 9, 9, 9, 9, 100]   [9, 0, 9, 0, 9, 0, 9, 0]
[0, 0, 0, 0, 0, 0, 0, 0]     [0, 9, 0, 9, 0, 9, 0, 100]
Input:                       Output:
[0, 1, 2, 3, 4, 5]           [0, 7, 14, 9, 4, 11]
[6, 7, 8, 9, 10, 11]         [6, 1, 8, 15, 10, 5]
[12, 13, 14, 15, 16, 17]     [12, 7, 2, 9, 16, 11]
Input:                       Output:
[0, 0, 0, 0, 0, 0]           [0, 2, 2, 6, 2, 6]
[1, 2, 3, 4, 5, 6]           [1, 0, 3, 2, 5, 2]
[2, 2, 2, 2, 2, 2]           [2, 2, 0, 4, 2, 4]
[9, 8, 7, 6, 5, 4]           [9, 2, 3, 0, 5, 2]
```
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the submission with the least amount of bytes wins!
  
[Answer]
## 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](http://pyth.herokuapp.com/?code=%3ElQC.e.%3EbkC%2B_PtQQ&input=%5B1%2C+2%2C+3%2C+4%2C+5%2C+6%2C+7%2C+8%2C+9%5D%2C%5B9%2C+8%2C+7%2C+6%2C+5%2C+4%2C+3%2C+2%2C+1%5D%2C%5B0%2C+0%2C+0%2C+0%2C+0%2C+0%2C+0%2C+0%2C+0%5D%0A&debug=0).
[Answer]
# 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>
```
[Answer]
## 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.](http://cjam.aditsu.net/#code=q~__W%251%3EW%3C%2B_z%2C_%40*%3Czee%3A%3Am%3Ez%5C%2C%3Cp&input=%5B%5B0%200%200%200%200%200%5D%20%5B1%202%203%204%205%206%5D%20%5B2%202%202%202%202%202%5D%20%5B9%208%207%206%205%204%5D%5D)
Most definitely golfable...
[Answer]
# Jelly, ~~29~~ ~~25~~ 24 bytes
```
ṖḊm-³;Z
,ZL€R_€/‘ż€Çị/€€
```
*Thanks for @Sp3000 for helping me golf off 5 bytes!*
[Try it online!](http://jelly.tryitonline.net/#code=4bmW4biKbS3CsztaCixaTOKCrFJf4oKsL-KAmMW84oKsw4fhu4sv4oKs4oKs&input=&args=W1swLCAwLCAwLCAwLCAwLCAwXSwgWzEsIDIsIDMsIDQsIDUsIDZdLCBbMiwgMiwgMiwgMiwgMiwgMl0sIFs5LCA4LCA3LCA2LCA1LCA0XV0)
[Answer]
## Ruby (2.2.2p95), 124 bytes
```
->*a{b=a.length;b<2?a:b.times.map{|i|d=i>0?-1:1;c=i;a[0].length.times.map{|j|r=a[c][j];c+=d;d*=-1if c==0||c==a.length-1;r}}}
```
This could probably be a lot better. I'll figure out how later!
[Answer]
# Japt, ~~55~~ ~~49~~ ~~41~~ 39 bytes
Wow, that was both really tricky and insanely fun.
```
C=2*Nl -2Nw £YoY+Ul)£NgLmX%CC-X%C)gY} ·
```
[Test it online!](http://ethproductions.github.io/japt?v=master&code=Qz0yKk5sIC0yTncgo1lvWStVbCmjTmdMbVglQ0MtWCVDKWdZfSC3&input=WzEsIDIsIDMsIDQsIDUsIDYsIDcsIDgsIDldCls5LCA4LCA3LCA2LCA1LCA0LCAzLCAyLCAxXQpbMSwgMiwgMywgNCwgNSwgNiwgNywgOCwgOV0=)
Outputs in reverse order to the examples. This will break slightly on inputs of more than 100 arrays; hopefully this doesn't make too much difference.
```
           // Implicit: N = array of input arrays, U = first input array, J = -1, L = 100
           // Let's use the first example. 3 input arrays, each of length 9.
C=2*Nl -2  // Set variable C to 2*N.length - 2. In the example, C is 4.
Nw      }  // Reverse N and map each index Y to:
YoY+Ul)    //  Create the range [Y...U.length+Y).
           //  The first time through (Y=0), we have   [0, 1, 2, 3, 4, 5, 6, 7, 8]
£       }  //  Map each item X and index Y to:
X%C        //   Take X mod C.                          [0, 1, 2, 3, 0, 1, 2, 3, 0]
C-X%C      //   Take C - (X mod C).                    [4, 3, 2, 1, 4, 3, 2, 1, 4]
Lm         //   Take the minimum of these and 100.     [0, 1, 2, 1, 0, 1, 2, 1, 0]
Ng         //   Get the array at the resulting index.
gY         //   Get the item at index Y in this array. [1, 8, 3, 6, 5, 4, 2, 7, 9]
·          // Join the result with newlines. I guess this isn't necessary, but it helps with readability.
```
### Non-competing version, 36 bytes
```
C=J+Nl)òC±C ®óUl)£NgLmX%CC-X%C)gY} ·
```
I had implemented these two number functions prior to the challenge:
* `ò` - same as `o`, but returns `[X..Y]` instead of `[X..Y)`
* `ó` - same as `o`, but returns `[X..X+Y)` instead of `[X..Y)`
But due to a misplaced `0`, they were buggy and always returned empty arrays. This has now been fixed.
[Test it online!](http://ethproductions.github.io/japt?v=master&code=Qz1KK05sKfJDsUMgrvNVbCmjTmdMbVglQ0MtWCVDKWdZfSC3&input=WzAsIDEsIDIsIDMsIDQsIDUsIDZdCls2LCA3LCA4LCA5LCAxMCwgMTEsIDEyXQpbMTIsIDEzLCAxNCwgMTUsIDE2LCAxNywgMThd)
[Answer]
# Python 2, ~~107~~ ~~106~~ ~~108~~ ~~105~~ 104 bytes
(Dropped some extra parens) (Wrong starting location (ب\_ب) ) (already had a list of that length)
```
def b(a):
 r,e=len(a)-1,enumerate
 print[[a[abs((i-o-r)%(r*2or 1)-r)][i]for i,_ in e(q)]for o,q in e(a)]
```
It's legal to have the input as an argument to a function, right? This is my first time submitting my code golf answer.
[Answer]
## APL, 33 chars
```
{(⍳≢⍵){0⌷(⍺-⍳≢⍉⍵)⊖⍵⍪1↓¯1↓⊖⍵}¨⊂↑⍵}
```
Assume ⎕IO←0.
The idea is that the bouncing movement can be obtained by simple shift upward of a matrix, if the original matrix is augmented along the first dimension with the matrix reversed with its first and last row shaved.
Graphically:
```
1 - - - - - 1 - - - -
- 2 - - - 2 - 2 - - -
- - 3 - 3 - - - 3 - 3
- - - 4 - - - - - 4 -
```
from
```
1 - - - - - 1 - - - -
- 2 - - - - - 2 - - -
- - 3 - - - - - 3 - -
- - - 4 - - - - - 4 -
- - - - 3 - - - - - 3
- - - - - 2 - - - - -
```
In APL `reverse` and `upward rotate` are the same symbol: `⊖`.
[Answer]
## Clojure, 125 bytes
Wow, this accumulated characters quite fast.
```
(fn[v](let[H(count v)r range R(r H)](for[i R](map #((v %2)%)(r(count(v 0)))(drop i(cycle(concat R(reverse(r 1(dec H))))))))))
```
Just trying to save bytes by `let`-defining frequently used values.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly)\*, 15 bytes
```
JṚŒḄṖṙ’Ʋị⁸Jị"$€
```
[Try it online!](https://tio.run/##y0rNyan8/9/r4c5ZRyc93NHycOe0hztnPmqYeWzTw93djxp3eAEpJZVHTWv@//8fHW2go4CCYnW4FKINdRSMdBSMdRRMdBRMdRTMwIJGYEEEAgta6ihY6CiYA9WAVZrExgIA "Jelly – Try It Online")
\* Newer version
]