[Question]
  [
Although it's done a few times as sub-challenge of a larger challenge, and we also have [a challenge to remove the borders of a square matrix](https://codegolf.stackexchange.com/questions/154686/perfect-squares-without-borders), I couldn't find a challenge to output the borders of a given matrix, so here it is.
## Challenge:
Given a rectangular-shaped matrix containing integers as input, output its borders.
## Challenge rules:
* The input is guaranteed to be a rectangular-shaped matrix (or empty)
* The input can contain negative and duplicated integers
* The output format and type is flexible and can be in any order (e.g. `[[1,2,3],[4,5,6],[7,8,9]]` may result in `[1,2,3,4,6,7,8,9]`; or `[[1,2,3],[6,9],[8,7],[4]]`; or `9\n8\n7\n6\n4\n3\n2\n1\n`; etc.). As long as it's clear that just the border of the input-matrix is output, *almost* every output-format is allowed. (If you're unsure whether an output format is allowed, feel free to ask in the comments.)
## General Rules:
* This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the shortest answer in bytes wins.  
Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.
* [Standard rules apply](https://codegolf.meta.stackexchange.com/questions/2419/default-for-code-golf-program-function-or-snippet/2422#2422) for your answer with [default I/O rules](https://codegolf.meta.stackexchange.com/questions/2447/default-for-code-golf-input-output-methods/), so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, full programs. Your call.
* [Default Loopholes](https://codegolf.meta.stackexchange.com/questions/1061/loopholes-that-are-forbidden-by-default) are forbidden.
* If possible, please add a link with a test for your code (e.g. [TIO](https://tio.run/#)).
* Also, adding an explanation for your answer is highly recommended.
## Test Cases:
| Input | Output | Visualized |
| --- | --- | --- |
| 
```
[[1,2,3], [4,5,6], [7,8,9]]
```
 | `[1,2,3,4,6,7,8,9]` | [enter image description here](https://i.stack.imgur.com/LjZP2.png) |
| `[[]]` | `[]` | N/A |
| `[[0]]` | `[0]` | [enter image description here](https://i.stack.imgur.com/dVfLm.png) |
| 
```
[[ 9, 2,-5, 3], [18, 3, 8, 0], [ 2, 7,21,-3], [ 9,-5,10,99]]
```
 | `[9,2,-5,3,18,0,2,-3,9,-5,10,99]` | [enter image description here](https://i.stack.imgur.com/k4K7g.png) |
| `[[1,2,3]]` | `[1,2,3]` | [enter image description here](https://i.stack.imgur.com/0PP16.png) |
| 
```
[[9], [8], [8], [9]]
```
 | `[9,8,8,9]` | [enter image description here](https://i.stack.imgur.com/fDjac.png) |
| 
```
[[ 10, 20, 30, 40, 50, 60], [ 70, 80, 90,-90,-80,-70], [-60,-50,-40,-30,-20,-10]]
```
 | 
```
[10,20,30,40,50,60,70,-70,-60,-50,-40,-30,-20,-10]
```
 | [enter image description here](https://i.stack.imgur.com/JkiUK.png) |
| 
```
[[ 1, 2, 3, 4, 5, 6], [ 7, 8, 9,10,11,12], [13,14,15,16,17,18], [19,20,21,22,23,24], [25,26,27,28,29,30], [31,32,33,34,35,36], [37,38,39,40,41,42], [43,44,45,46,47,48], [49,50,51,52,53,54], [55,56,57,58,59,60]]
```
 | 
```
[1,2,3,4,5,6,7,12,13,18,19,24,25,30,31,36,37,42,43,48,49,54,55,56,57,58,59,60]
```
 | [enter image description here](https://i.stack.imgur.com/P4Sym.png) |
| 
```
[[-11, 18,  3,-40,123], [ 18,-33,  9,765,100]]
```
 | `[-11,18,3,-40,123,18,-33,9,765,100]` | [enter image description here](https://i.stack.imgur.com/cHcQ8.png) |
| 
```
[[14, 3], [ 3,14], [14, 3], [ 3,14], [14, 3]]
```
 | `[14,3,3,14,14,3,3,14,14,3]` | [enter image description here](https://i.stack.imgur.com/TGhXM.png) |
 
  
[Answer]
# Python 3, 38 bytes
```
def f(x):
 for c in x[1:-1]:c[1:-1]=[]
```
[Outputs by modifying arguments](https://codegolf.meta.stackexchange.com/a/4942/70761). The code also works on Python 2.
Explanation: deletes the center part of each center row by modifying the original input.
[Attempt This Online!](https://ato.pxeger.com/run?1=dVPLbttADDz05q_gKbCAWcDc9xrolwhC0aZ264sSKAqQfEsvuST_1H5NZ7VOgVYqDGrXJIfkDKUfb_fP8_e78eXl9XE-m_zz5uvpLOf9U3fcyfluklu5jPLU69HocLxt58d-aNm_Pnyp6fPpYd5fFgSPnUyn-XEa5bK7ny7jvF_Cfa-wcAN6j4DIMyGjDEPX_Z12AH9rtxJhaW4TUYOwG6jaE34J80SoFdAmWCWvPOtOiySfqiTT5_HbaR-74V9X6FYwKRALEyDkv5NeM28QPg_LfwYlwSpMizOfyXpA2dCnybhylwHS5z-PDaCwoFiao3laoMXrBIn3TCsHmGq8m9RiJvLOXEOMIdawhtGNFYlWmpWZZ3HWvpZemJbKRxVqmwQO6qFkGaEJmpu3gMUphOU2HaxfvDbARlgqlGELXBvLKRyVcHAeLsC1bi7BZbgCDusVvnXz3LmHD_ARPsG3br6AtIIiWASH0LqFgBAREkJGKIgbRA15SF0iuVZV1F73Rp_hREK2KdYNbr3I_v01kKpB4_1fH-HtU3v_QH8D) (additional test cases taken from [loopy walt's answer](https://codegolf.stackexchange.com/a/260961))
[Answer]
# [Japt](https://github.com/ETHproductions/japt), ~~10~~ 8 [bytes](https://en.wikipedia.org/wiki/ISO/IEC_8859-1)
I/O as a 2D array of integers, with output sorted anti-clockwise starting in the bottom right corner.
```
4√Ü=z)o√Éf
```
[Try it](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&code=NMY9eilvw2Y&input=W1sgMSwgMiwgMywgNCwgNSwgNl0sCiBbIDcsIDgsIDksMTAsMTEsMTJdLAogWzEzLDE0LDE1LDE2LDE3LDE4XSwKIFsxOSwyMCwyMSwyMiwyMywyNF0sCiBbMjUsMjYsMjcsMjgsMjksMzBdLAogWzMxLDMyLDMzLDM0LDM1LDM2XSwKIFszNywzOCwzOSw0MCw0MSw0Ml0sCiBbNDMsNDQsNDUsNDYsNDcsNDhdLAogWzQ5LDUwLDUxLDUyLDUzLDU0XSwKIFs1NSw1Niw1Nyw1OCw1OSw2MF1dCi1R)
```
4√Ü=z)o√Éf     :Implicit input of 2D array U
4√Ü           :Map the range [0,4)
  =          :  Reassign to U
   z         :   Rotate U 90¬∞ clockwise
    )        :  End reassignment
     o       :  Pop last sub-array, mutating the array
      √É      :End map
       f     :Filter, removing null elements
```
[Answer]
# [jq](https://stedolan.github.io/jq/), ~~57~~ ~~46~~ 20 bytes
```
del(.[1:-1][][1:-1])
```
[Online demo](https://jqplay.org/s/Y-niTUhPziP)
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), ~~47~~ 45 bytes
-2 bytes thanks to @alephalpha
[Try it online!](https://tio.run/##bZBNa8MwDIbv@RWGQOk6h9rOBwshpdfuVEZuRgNvdVcf4hRHN5P@9SzL2FZ3BV1e9DxCUqvwpFuF5l2Nb507aFePu6NsnOSvMWwE9bGUWHtOEz4A0CmJqkoERYCBxrAYUffISU32yqFB01n5ouyHliVQkkIVfU@VMwbr9d4Zi1H0FcVkeT8MASNCJp0ZdgOlIZRNUOOU7c9dr7fel5Q8zVXeeFno5fXf0kvOVj@LP1yeO2Mvy4QzRh7JdYeSIrwpD0cWdz5RMPinFb/a@Ak)
```
If[Tr[1^#]>2,{#[[t={1,-1}]],#[[2;;-2,t]]},#]&
```
**Explanation**
`Tr[1^#]` returns the length of the shortest dimension by computing the `Trace` of a matrix of 1's with the same dimensions as the input, i.e., `Min@Dimensions@#`. If we have an edge case with a dimension of 0, 1, or 2, we return the input in its original form.
If `Tr[1^#]>2` is true, then we use Mathematica's `[[a;;b, c;;d]]` syntax to access different parts of the matrix: `#[[{1,-1}]]` returns the first and last rows, `#[[2;;-2,{1,-1}]]` returns the first and last columns while excluding the "corners." We return a ragged array as the output: if the input is `m`x`n` with `m`,`n>2`, the output will be of the format `{(2 x n array), ((m-2) x 2 array)}`
[Answer]
# Excel, 77 bytes
```
=TOCOL(B2#/(MAP(B2#,LAMBDA(b,SUM(SUBTOTAL(2,OFFSET(b,{-1;1},{-1,1})))))<4),2)
```
Input is spilled range deliberately set to have its top-leftmost cell as `B2`, rather than the customary `A1`, such that the four cells above, below, to the right and to the left of that cell exist.
[Answer]
# [Rust](https://www.rust-lang.org), 81 bytes
```
|a,b,c|(0..).zip(a).filter(move|(d,_)|d%b<1||d%b>b-2||d/b<1||d/b>c-2).map(|a|a.1)
```
[Attempt This Online!](https://ato.pxeger.com/run?1=TVBBasMwELz7FZtAQYK1YjsNjVVXvfTaQy-9lGJkWQaB7RhbySFRXlIKPrSPym8qx4V2WWZ2h2FY9uOr3w92vDxVLTTStITCKai1hYpXLXnVKjODOWqB-4lmpKEYbMm5sbrn_Fl2WY65gAf43tsq3F5enMQClSMRY5QdTUckZZWpvZ00u4N2pMScuvKmyGI3kSjCxA-reV8VQoUJZY3siJNOspj-Bn_eB0HXm9bW7YIsT_zxvESoSAAAB60Wb5AiJBhuENYIG5z0a8Xbq-IxQrj7073Zr0mM4Rrj5J-eTiFxhGnqO32fwuCWMrWra60s55l_jMf5NYJQ6g87z0eO48w_)
Takes input as a flattened matrix with size given as `b` and `c`
[Answer]
# JavaScript (ES6), 54 bytes
```
m=>m.map((r,y)=>r.filter((_,x)=>x*y/r[x+1]?!m[y+1]:1))
```
[Try it online!](https://tio.run/##fZDBbsIwDIbvPEV3a7c/rI7jpJkEe5CqmtAGExOlqKAJnp65NBw2wQ5OHMf2Z/9fi@/F/r1f7w5m230sz6vZuZ3N22m72OV5j1Mxm/fT1XpzWPZ5/oajvo@Pp@e@Pj5R8/rQ1ie9X6gozu/ddt9tltNN95mv8nqSZTXBghsMroPAj25AhdhMmqKY/Kmpm1vB8lZ0aJRFZBZGkCUIVeoi07McA/qdBViCSRlaovlUIt6ZYBz5DjCOTapf1@1GF5hyMqvGak5N1Px1tKCPSi2WMIOpb0L6NF4fmm20ymi10S6Gyn9IgxLD7k4pCrkyLmLEYWEikE0yMciBVAcPCqC0CEUoRsWyFpZh3Ri2AuthVcYKNoLTiExglYrBDizghOQArsAROrkjuIR0DOfgBM7DBbiEdBG6pRDEQhiSkCIQDwmQChLhx8XPPw "JavaScript (Node.js) ‚Äì Try It Online")
Or **58 bytes** (ES10) if we want to flatten the output:
```
m=>m.flatMap((r,y)=>r.filter((_,x)=>x*y/r[x+1]?!m[y+1]:1))
```
[Try it online!](https://tio.run/##fZDdbsIwDIXveYrurt1OWB3np5kEe4I9QVVNFaMTU6GooAmevnNpuNgEu3DiOLY/@3zV3/Vh1W/2R7XrPtZDsxi2i@V23rT18a3ep2mPc7ZY9vNm0x7XfZq@4yTv0@P5uS9PT1S9PmzLs9wvlGXDqtsdunY9b7vPtEnLWZKUBA2uMLoGFm5yPQqEalZl2exPTVndCua3omOjJCDRUBZJhFAhLhI58ykg34mHJqiYISWSTznCnQmmke8Aw9Sk@HXdbnSBCSfRYixmxKyYu47m5VGIhRxqNPGVj5/KyUOylVQpqVbSRVH@D2lUYtzdCEUgV8ZFjDAuTATSUSYGGZDo4EAeFBehAMGIWFpDM7SZwtpCO2iRsYAO4DgiE1ikYrABW3BEsgcX4ACZ3BBMRBqGMTAWxsF4mIg0AbKlJVgNy7ARaS2sg/WwBWyAmxYffgA "JavaScript (Node.js) ‚Äì Try It Online")
### Commented
```
m =>                 // m[] = input matrix
m.map((r, y) =>      // for each row r[] in m[] at index y:
  r.filter((_, x) => //   for each value in r[] at index x:
    x * y            //     if neither x nor y is equal to 0 and there's
    / r[x + 1] ?     //     at least one more column after this one:
      !m[y + 1]      //       keep the value only if this is the last row
    :                //     else:
      1              //       keep the value
  )                  //   end of filter()
)                    // end of map()
```
[Answer]
# [J](http://jsoftware.com/), 24 20 bytes
```
#~&,_>_(<,~<<0 _1)}]
```
[Try it online!](https://tio.run/##y/qvpKeepmBrpaCuoKNgoGAFxLp6Cs5BPm7/levUdOLt4jVsdOpsbAwU4g01a2P/a3KlJmfkK6QpZOqZKJiCOerqMDEdPUt0EStDBSMFY0x1ChZAaPkfAA "J ‚Äì Try It Online")
* `_(<,~<<0 _1)}]` Convert all interior points to infinity, by specifying "not first and last (0 and -1)" elements of first axis, and "not first and last" elements of second axis.
* `_>` Where is that matrix less than infinity? Returns a 1-0 mask selecting the border
* `#~&,` Flatten and filter the input with that mask
# diagonal rotation, 24 bytes
```
#~&,_=[:+/,.~@1 _1|.!._]
```
[Try it online!](https://tio.run/##ZYzNCoJQEIX3PsWkol4cR28/kNMVLgWtokXbEBehZJsewJ9Xt9sFiYphBs75zpzH5FLYQMEQAkIGbDYhOFxOx8kbA6yKK8cp0qglVLKnBVXlJJzznuCNFWs/C2rS3LvS97gl7VvYGRglZI7CUanMPIugE/oTIIN240wwwI4t8ONUR0WKskhLIeOvUjIhNM1yYD1QZLVwpVPf7k9ooKU1bKwIw9lDyn8dlrCE1X8Otmby6QU "J ‚Äì Try It Online")
Looks like this may be related to Adam's APL answer, but was discovered independently. See alternate below for a different approach.
1. Diagonally rotate the matrix up-left using infinity as fill.
2. Same thing down-right
3. Add the two together (now the borders will all have the value infinity)
4. Create a border-selecting 1-0 mask with 1 wherever infinity is
5. Use that mask to filter the input, flattening both the mask and the input
# original, 24 bytes
```
#~&,0=<:@$*/@:|"1$#:i.@$
```
[Try it online!](https://tio.run/##ZczNCsIwDAfw@54ibGVbXZe2foCrLRQFT@LBu3iQDefFB5jbq9euMPwiJJD8/uTuYswaMAoyYCBA@S4RdqfD3iVDyoTRypIZt@oZS5KoFi1xNDpuEUYeUaQ1fnLAzmNeoh@aDVoLuEiadtS@A@hpM0zCUtapAKTgNjecScPPVBZfT9GHmP8se2V7zMNOYxnV19sDGmhxCauwZNl0Y1j9XpSEOSz@c7D2VbkX "J ‚Äì Try It Online")
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal), 62 [bitsv1](https://github.com/Vyxal/Vyncode/blob/main/README.md), 7.75 bytes
```
4(‚à©·∏£·πò)_W'
```
[Try it Online!](https://vyxal.pythonanywhere.com/?v=1#WyI9IiwiIiwiNCjiiKnhuKPhuZgpX1cnIiwiIiwiW1s5XSwgWzhdLCBbOF0sIFs5XV0iXQ==)
Port of pyth messed up by the fact that `·∏£` and `·π´` return `0` on an empty list instead of erroring (which has its use, but is annoying here)
## Explained
```
4(‚à©·∏£·πò)_W'
4(   )    # 4 times
  ‚à©       #   transpose top of stack
   ·∏£      #   separate the head from the rest
    ·πò     #   and reverse
      _W  # pop the remaining list and wrap the stack in a list
        ' # remove 0s and empty lists
```
[Answer]
# [R](https://www.r-project.org), ~~44~~ 34 bytes
```
\(m)m[rev(d<-row(m)<2|col(m)<2)|d]
```
[Attempt This Online!](https://ato.pxeger.com/run?1=dZBLCsIwEIZx21MEVwnMQNJWbYquvYA7dSF9iGAVQn0svImbKngoPY1_LeiilfBlHv8_Gcj15qp7PnkcypyjZ38hC1XMXXaU6Zjd_oRy7F-S_faTqEu6bJyv3lQWk2JVus1ZmthSQDRTysvh837KZldm68xJ1ZZ0u5VIS8InHpAIyBMmqqPArVFBECPyDXGtCVvbjCZrFYWdu00ckOleEuFgrlvGo8IHAQjBAAzBCETAauIa5IweQ2N4GF7GDGOWjVZ_fsTE8GPFV2v-s6qa-AY)
Footer stolen from [pajonk's answer](https://codegolf.stackexchange.com/a/260945/64121), and -10 thanks to them!
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 8 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
*With the lax output requirements I was expecting to find terser in Jelly!*
```
≈íD·ªã@·∏ä¬°‚Ç¨.
```
A monadic Link that accepts the rectangular matrix and yields a list of lists of border values.
**[Try it online!](https://tio.run/##y0rNyan8///oJJeHu7sdHu7oOrTwUdMavf@H249Oerhzxv//0dEKhgY6CkZAbAzEJkBsCsRmBrE6XArRCuZAtgUQWxro6IIwkK1rDpHTNQOygWp1gXp0gXp1gWboGoLkYgE "Jelly ‚Äì Try It Online")** Or see the [test-suite](https://tio.run/##TU87TsQwEO33FC5okJ5RxjNjxwWIAolDRClpVnsBuoUGCbqtKKCgp16BkCiC9iDJRcIkzkpbPGccv3mf9d1mcz@Oh91N//Ny3X89dx/D4@fFeIu/p8Ou/349Ww/bt25/eeWG7fv5enj47fbdfhybVdMQXIDjFivXCJzCxXlOcDVcbu3SNOWsysflacXrcYuMxzO7mu@TXkIg@PJufCNThbyoEQK4jHlm1CfnwnHGd8HABjGoIS4GyebakCv4CTb7VN58tNm43na87XrT8HRMvpQ1xZOmbqk6RSQChdKKQQKy4BGUQCUdZZigdQsBgRFk/hsUISJY6Rohg0sUJrAVZbCAFVzcOIFrcIYFFIIUN2GIQBQSIQlS3CTDqihBA5ShxU0VGqEJWkMz4lyu/Qc "Jelly ‚Äì Try It Online").
### How?
```
≈íD·ªã@·∏ä¬°‚Ç¨. - Link: list of lists, M
≈íD       - all NW-SE diagonals of M
       . - set the right argument to 0.5
      ‚Ç¨  - for each diagonal:
     ¬°   -   repeat...
    ·∏ä    -   ...number of times: dequeue (i.e. once if diagonal length > 1)
   @     -   ...action: with swapped arguments - f(0.5, diagonal)
  ·ªã      -                index into*
             
             * fractional indices give the two neighbours in the 
               case of 0.5 that's 0 (the last) and 1 (the first)
```
[Answer]
# [SAS IML](https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/imlug/titlepage.htm), 88 ~~70~~
Input is a rectangular matrix `M` e.g.,
```
M1={
 1  2  3  4  5  6,
 7  8  9 10 11 12,
13 14 15 16 17 18,
19 20 21 22 23 24,
25 26 27 28 29 30,
31 32 33 34 35 36,
37 38 39 40 41 42,
43 44 45 46 47 48,
49 50 51 52 53 54,
55 56 57 58 59 60
};
```
[EDIT:]
According to comments below I updated the answer.
The code (an IML module):
```
start d(M);if 2<nrow(M)><ncol(M) then M[2:nrow(M)-1,2:ncol(M)-1]=.;M=M[loc(M>.)];finish;
```
Human readable:
```
start d(M);
  if 2 < nrow(M)><ncol(M) then 
    M[ 2:nrow(M)-1, 2:ncol(M)-1 ] = .; 
  M = M[ loc(M > .) ];
finish;
```
To execute the IML module `d` run the following:
```
call d(M);
```
The process:
1. For a Matrix M with at least 3 rows and columns (`2 < nrow(M)><ncol(M)`, where `nrow(M)` is number of rows, `ncol(M)` is number of columns, and `><` is operator of minimum of two numbers) replace "everytnig inside" (`2:nrow(M)-1, 2:ncol(M)-1`) with missing data (`.`),
2. select those elements of `M` where value is not missing.
To print out result, i.e. elements extracted from `M`, run the following line:
```
if type(M)="U" then print "M is Empty";
else print M;
```
---
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 7 bytes
```
≈íD¬µ≈º·π™·∏¢)
```
[Try it online!](https://tio.run/##TU87TsQwFOz3FG5XGkt5PzvuuQSKtqRBewFOQL8VNSU9EkhUoD3IniRM7CBRvJdx3ryZeY8P5/PTul4vd9/v16/b59vt4/W4/jxfL7fPl@P9ui6HZREo7IRDWhyB0lHFjHYiXJbRp/FJDUmRA2lsyEyExD71N4epQgV5zMknWSa0XW2Yddg6Y/7Xd04iPynLWM4KVtkNKvHMahPyVsS5jlkuxORm7mTuZmpk@UsuW/ItrFOQertcD9@2iCIQHVcZxCEMXiAVMtJJAwV5myrUoN7/akALlEfP0AYbUUxgPNRgDgvYcLMKm2ENDOgCH25ucIcHvMArfLh5A08JQSjCEMMtAlEQFTEjGko/7vQL "Jelly ‚Äì Try It Online")
No shot I could have thought of using diagonals if @Jonathan Allan hadn't first, so go upvote [his solution](https://codegolf.stackexchange.com/a/261008/85334)! (Also, two bonus 8-byters: `≈íD¬µ·πô-·∏£2)`, `≈íD¬µ·∏ä·πñ≈ì^)`)
```
≈íD¬µ   )    For each diagonal of the input:
    ·π™      take and remove the last element,
   ≈º       zip with the remaining elements,
     ·∏¢     and take the first of those pairs.
```
My original solutions, to laugh at:
# [Jelly](https://github.com/DennisMitchell/jelly), 9 bytes
```
·∏ä·πñ$‚Å∫‚Ç¨F≈ì^F
```
[Try it online!](https://tio.run/##TU8xTsQwEOzvFS5okMZS1rtrxx@4P6AodDToPkAJDRIlSIhH8ACOFt1D7j4SJnaQKHYzzs7OzN7fHQ4Py3L@ejkf368uj9@Xp8/96e12v/w8n17Px4/rm2WZdtMkSNAZuzAZHLmhghF1Jpym3of@CRUhITpC35CRCIF9aG8OQ0ESxD4nn2QZUDe1btZgbYzxX984gfyQWMoylrPyZlCIR1YdENcijqXPYiYmN3IncjdSI8pfclmTr2GNgtTb5Fr4ukYUgaR@lUIMwuAZUiA9nVRQkLelhKRI1v4mR8pIPHpEqtAeRQXKQxVqUId2Ny3QEVrBgCaw7mYKM5jDMqzAuptV8BQXeIIrvLu5wzO8wEd4RW7Hzb8 "Jelly ‚Äì Try It Online")
```
·∏ä·πñ           Remove the first and last rows
  $‚Å∫‚Ç¨        and columns.
     F       Flatten the result,
        F    flatten the input,
      ≈ì^     symmetric multiset difference.
```
Can't decide if this feels worse...:
# [Jelly](https://github.com/DennisMitchell/jelly), 9 bytes
```
·∏äUZ∆ä3√ê¬°Z·∏¢
```
[Try it online!](https://tio.run/##TU87TkNBDOxzim2RZqXntb2fg1CQp5Q0KBfgBEipEBUtnCJpieAeOclj3u5DorDf7PN4Zvz0eDw@L8vtfLrf/5z0@vr1sb@dP5fry/fb7fJ@97As826eBQl6wC7MBkfuqKCiHQjnefRpfEJDSIiOMDakEiGwT/3NYShIgjjm5JMsE9qmNsw6bJ1R//WNE8gPiaUsYzkrbwaFuLLahLgWcSxjFjMxuZE7kbuRGlH@ksuafA1rFKTeJtfDtzWiCCSNqxRiEAbPkAIZ6aSBgrwtJSRFsv43OVJG4tEVqUFHFBUoD1WoQR063LRAK7SBAU1gw80UZjCHZViBDTdr4Cku8ARX@HBzh2d4gVd4Q@7HHX4B "Jelly ‚Äì Try It Online")
```
   ∆ä3√ê¬°      Repeat [0, 1, 2, 3] times:
·∏ä            Remove the first row,
 U           reverse each row,
  Z          transpose.
       Z     Transpose the results
        ·∏¢    and return the first row of that.
```
[Answer]
# [Pyth](https://github.com/isaacg1/pyth), 7 bytes
```
V4.)=_C
```
[Try it online!](https://tio.run/##K6gsyfj/P8xET9M23vn//@hoQx0jHeNYnWgTHVMdMyBtrmOhYxkbCwA "Pyth ‚Äì Try It Online")
Prints each side as lists separated by newlines. Goes clockwise starting with the left side.
### Explanation
```
V4.)=_CQ    # implicitly add Q
            # implicitly assign Q = eval(input())
V4          # loop 4 times
    =  Q    #   assign Q to
      CQ    #   Q transposed
     _      #   and reversed
  .)        #   pop the last element of Q and print it
```
[Answer]
# [Python 2](https://docs.python.org/2/), 48 bytes
```
f=lambda a:a[:1]+a[1:][-1:]+map(f,a[1:-(a>[f])])
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m728oLIkIz_PaMGCpaUlaboWNw3SbHMSc5NSEhUSrRKjrQxjtROjDa1io3WBhHZuYoFGmg5IQFcj0S46LVYzVhOq72BBUWZeiUaaRnS0oY6RjnGsTrSJjqmOGZA217HQsYyN1dTkQqgx0AFCNDFDoFojIDbGVAuS0TFCVw-yR8cELAekdUxBenUgtqKqROUic0y1os20osEugXgEFhAA)
Takes a LOL and returns a ragged LOL. Output for non degenerate inputs is [top row,bottom row,[1st,last]of 2nd row,[1st,last]of 3rd row,...
[Answer]
# [APL (Dyalog Unicode)](https://www.dyalog.com/), ~~23~~ ~~22~~ 18 bytes
Thanks to ovs for ‚àí4 bytes.
Anonymous prefix lambda.
```
{‚çµ[‚ç∏‚à®‚àò‚åΩ‚àò‚äñ‚ç®1‚àä¬®‚ç≥‚ç¥‚çµ]}
```
[Try it online!](https://tio.run/##RU@9SgNBEO59iu2i8C3c7OzPbW2jFgrG7rgiILEJaCtiJYQQvKBFxEdIIVioYGOTR9kXOWc3JhYzOzs/38/oZqIvb0eT66u@v0vdV5O67zRbpdlrevzJef6SuhWl2Xy9St1H6j5lqb3vx2n6tJ@6RZo/pO5N2ut3TtPntFgOzw8lXxwdDw9yQyAWy5Ph2Wk/HjQNwYBbqMbCwecioEZs28FeHm/faluoCGWgHVS5oloKKMlV/spIBRiCLlNZlk2qEHeAG76/T8xL9S7tlpScKCPBElbCSfgNQ5CylogVdA6pdSgj7aWUTS0XWi61IGj6V05ZeVZrBVDwNnBFfMwiiUCmmGKQBYlyDwqgIo4iBE@sGQPDMDY3jYPxMGK5hongooMJLCYZbMEOXIg4gGtwhIizBFuILMNaWAfrYQNsIbIRYsIRnIFjuELkHJyHC3A1XITPrn4B "APL (Dyalog Unicode) ‚Äì Try It Online")
`{`‚Ä¶`}`‚ÄÉ"dfn"; argument is `‚çµ`:
‚ÄÉ`‚çµ[`‚Ä¶`]`‚ÄÉselect from the argument:
‚ÄÉ‚ÄÉ`‚ç∏`‚ÄÉwhere indicated by
‚ÄÉ‚ÄÉ`‚à®‚àò‚åΩ‚àò‚äñ‚ç®`‚ÄÉthe following mask when ORed with its mirrored flipped version‚Ä¶
‚ÄÉ‚ÄÉ`1‚àä¬®`‚ÄÉtrue only where 1 is a member of
‚ÄÉ‚ÄÉ`‚ç≥`‚ÄÉthe indices for an array that has the shape
‚ÄÉ‚ÄÉ`‚ç¥‚çµ`‚ÄÉthe shape of the argument
[Answer]
# [Haskell](https://www.haskell.org/), 48 bytes
```
b=zipWith($)[head,map last,last,map head].repeat
```
[Try it online!](https://tio.run/##y0gszk7Nyfn/P8m2KrMgPLMkQ0NFMzojNTFFJzexQCEnsbhEB0yAeCDhWL2i1ILUxJL/uYmZebYFRZl5JSpJ0dGGOkY6xrE60SY6pjpmQNpcx0LHMjb2PwA "Haskell ‚Äì Try It Online")
# [Haskell](https://www.haskell.org/), 74 bytes
```
import Data.List;(o:t)#(r:s)=r++t#(reverse$transpose$s);_#_=[];b=("1234"#)
```
[Try it online!](https://tio.run/##DcZLCsMgEADQq5SYhZKhkE9/EXdd9gYiwYBQSWJkZuj1rav3vp62sO@lxCOfyJe3Z3/9RGItz5mVkDiTMth1XBt@ASm0jD5RPutI6UUsxjq9Gtn0wzg1QpXDx2QyxsTtam0PA4wO7AQ3uFcf8ISXc@UP "Haskell ‚Äì Try It Online")
At each of the four or less iterations, `#` peels the top row `r` from the matrix, and rotates it i-wise by `transpose` sending corner 2 to 3 and `reverse` sending corner 2 from 3 to 1 before reiterating for one side `o` less than before.
[Answer]
# [R](https://www.r-project.org), 52 bytes
```
\(m)m[row(m)%in%c(1,nrow(m))|col(m)%in%c(1,ncol(m))]
```
[Attempt This Online!](https://ato.pxeger.com/run?1=dZBBCsIwEEVx21NkIyQwA5m2alNw7QXcqQspVgq2Qqnowpu4qYKH0tP4S0AFK-FlMvP_ZGAu17q95dP7ock5ecRLXZpyUe-PiMOiGmZaqPKpOWf73XfZp2ble5-DmS6n5bqpi5OW1FFENDcmyOEJPkpRNZvtptbmV7K_pUw7UiHxiFREgZKkiwq3RQZBTSgU4k5TrrOJJecMxb2zJY1I-ockOOjrl_GpCkEEYjACYzABCXCWuANvRo2hMTwML6OH0ctizZ-NSAo_Rrw1v8-29fEF)
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 18 bytes
```
Ôº©Œ£Ôº•Œ∏Œ¶Œπ¬¨‚àßÔπ™Œ∫‚äñÔº¨Œ∏Ôπ™Œº‚äñÔº¨Œπ
```
[Attempt This Online!](https://ato.pxeger.com/run?1=bY7BCoJAEIbvPcXgaYQR1IiUTpF0ygg6Lnsw3VLS3dS1l-nioahX8m1aUDo1h-Hn_7_5mccnzZMmVUnZ969On51g0IemkBo3Savx2FUYJzesCbZFqUWDBcFeaVzLDGOVdaXCK0Ek0kZUQmqR4U7Ii86xtm2bYEKqv0hh_2b1bE9pO33wZpZzLy0-RIwxCAl8chYEc04zAOYFRhKY7Y6GiWFJvkfORJgTw3suhSHnfOz8Ag) Link is to verbose version of code. Explanation: Uses a filter to keep elements in the first or last row or column i.e. those that are not both in an interior row and in an interior column.
```
   Œ∏                Input array
  Ôº•                 Map over rows
     Œπ              Current row
    Œ¶               Filtered where
         Œ∫          Current row
        Ôπ™           Modulo
            Œ∏       Input array
           Ôº¨        Length
          ‚äñ         Decremented
       ‚àß            Logical And
              Œº     Current column
             Ôπ™      Modulo
                 Œπ  Current row
                Ôº¨   Length
               ‚äñ    Decremented
      ¬¨             Logical Not
 Œ£                  Flatten
Ôº©                   Cast to string
                    Implicitly print
```
[Answer]
# [julia](https://julialang.org/), 59 bytes
Expects a `Matrix{Any}` and returns a `Vector{Any}` of the border entries.
Each call of this function pops the top row of the matrix, rotates the resulting matrix to the right and recurses. Terminates after 4 iterations or when the resulting matrix is empty.
```
f(M,c=4)=length(M)c>0 ? [M[1,:];f(M[end:-1:2,:]',c-1)] : []
```
[Attempt This Online!](https://ato.pxeger.com/run?1=ZZFLasMwEIbptqf4d5HAgpHfD5LuuqpPILwwjh27GDe4MhTanqSbbHKo9jQdxxSKDSMx-vXPfHp8XZ-nvisvl-tkGxV_Z43InWrvy31fDyfbilxWB8IDTG60kxbzvqmHY6p06vJ651RKywIpTLG0-Ll7aoTRcOFl8BEgzBAhRlJIfBxwHrvB9sM99ynt2L29P_YvpQ39TzENx7pxQBxyZW2r0oqNahKGqGDm6BgeMyhjJYKroVhM5k1NSDbo5Xhr9UYxSYb4Fly1KSO4BI_gEwJCyLyIEDOCoObBqYpYVSEn7FBsVOxXXKY0rYlj_dqW51roNORrC81TKOXuv2t51L__-QU)
[Answer]
# [Scala](https://www.scala-lang.org/), 98 bytes
Golfed version. [Try it online!](https://tio.run/##lU1NS8QwEL3vr5hjwk5K2@03rOBRUC8eZSmxplipSTcJi7Dub6/TaotHN/Am783Me@Ma2cvRvLyrxsOD7DSoT6/0q4PbYYDz5iR7aCv2pI7Pd9ofcCKLOPD9zcJhDyMzeKTW/H1I37ydG@kUsMeux5p/sRqJ/fEw/jOv0VaVo4HdbltmAi/J4AJvpXaDcSqw6qSsU/wybgAG22nfa9YyFoE3kPDAm/vOeYSpsrlEGOOO/3YSTDFbRI4Flpzef6NKhBhFirDmRQUJBKrh0ooRcowjFOtSOXmiEMurjpEBYsKOkBBSQrZeyUkVhDJEMYG4yNepyEiSQZBRUICgIBGF8/nL@A0)
```
(o,q)=>(o,q)match{case (Nil,_)|(_,Nil)=>Seq[Int]()case (_,r::s)=>r++f(o.tail,s.transpose.reverse)}
```
Ungolfed version. [Try it online!](https://tio.run/##lU5dS8MwFH3frziPCbspbdeu7WCCj4L6B2SM2KWsMtuSBBF0v73elK3uUQPnknNzPuJqfdLj2L@@mdrjSbcdzKc33cHhfhjwtQAOpkEj@g0eW@dfHjq/I1h3ofNuJ28E2EL0QSXxrn19nHKAWjsD8dyeCHuJb4g9gZnE9u7XK@SNlgUWmw3cpLFYLsNXIq9Dhou81Z0bemciaz6MdSZ4zwseg207f@pEI0QC3yOTke9DB01NYhoJpbSSl01GOa2vpKCSKsnnr1EVISWVE@a8pGRC4BlfVymhoDQhNYuq4Eliqv5VxgakjBUjY@SM9dxSMCsZVUwqgO@qmF/VmikbFBsVBygOUkk81Z8X4/gD)
```
object Main extends App {
  def f(o: List[Int], rs: List[List[Int]]): List[Int] = (o, rs) match {
    case (Nil, _) | (_, Nil) => List[Int]()
    case (_, r :: s) => r ++ f(o.tail, s.transpose.reverse)
  }
  println(f((1 to 4).toList, List(List(1,2,3), List(4,5,6), List(7,8,9))))
  println(f((1 to 4).toList, List(List(9, 2,-5, 3), List(18, 3, 8, 0), List(2, 7,21,-3), List(9,-5,10,99))))
  println(f((1 to 4).toList, List(List(10, 20, 30, 40, 50, 60), List(70, 80, 90,-90,-80,-70), List(-60,-50,-40,-30,-20,-10))))
}
```
[Answer]
# [Vyxal 3](https://github.com/Vyxal/Vyxal/tree/version-3) `·π°`, 6 bytes
```
·∏£·π´$·µõ√ûh
```
[Try it Online!](https://vyxal.github.io/latest.html#WyLhuaEiLCIiLCLhuKPhuask4bWbw55oIiwiIiwiW1sgMSwgMiwgMywgNCwgNSwgNl0sWyA3LCA4LCA5LDEwLDExLDEyXSxbMTMsMTQsMTUsMTYsMTcsMThdLFsxOSwyMCwyMSwyMiwyMywyNF0sWzI1LDI2LDI3LDI4LDI5LDMwXSxbMzEsMzIsMzMsMzQsMzUsMzZdLFszNywzOCwzOSw0MCw0MSw0Ml0sWzQzLDQ0LDQ1LDQ2LDQ3LDQ4XSxbNDksNTAsNTEsNTIsNTMsNTRdLFs1NSw1Niw1Nyw1OCw1OSw2MF1dIiwiMy40LjEiXQ==)
Abuses formatting quite a bit but there isn't a way to get diagonals yet.
```
·∏£·π´$·µõ√ûh¬≠‚Å°‚Äã‚Äé‚Äé‚Å™‚Å°‚Å™‚Å†‚Å™‚Å°‚Å™‚Äè‚Å†‚Å™‚Å™‚Å†‚Å™‚Å™‚Äè‚Äã‚Å°‚Å†‚Å°‚Äå‚Å¢‚Äã‚Äé‚Äé‚Å™‚Å°‚Å™‚Å†‚Å™‚Å¢‚Å™‚Äè‚Å†‚Äé‚Å™‚Å°‚Å™‚Å†‚Å™‚Å£‚Å™‚Äè‚Äè‚Äã‚Å°‚Å†‚Å°‚Äå‚Å£‚Äã‚Äé‚Äé‚Å™‚Å°‚Å™‚Å†‚Å™‚Å§‚Å™‚Äè‚Å†‚Äé‚Å™‚Å°‚Å™‚Å†‚Å™‚Å¢‚Å°‚Å™‚Äè‚Å†‚Äé‚Å™‚Å°‚Å™‚Å†‚Å™‚Å¢‚Å¢‚Å™‚Äè‚Äè‚Äã‚Å°‚Å†‚Å°‚Äå¬≠
·∏£       # ‚Äé‚Å°head extract
 ·π´$     # ‚Äé‚Å¢tail extract and swap 
   ·µõ√ûh  # ‚Äé‚Å£vectorized edges
üíé
```
Created with the help of [Luminespire](https://vyxal.github.io/Luminespire).
[Answer]
# [Retina](https://github.com/m-ender/retina/wiki/The-Language), 23 bytes
```
(?<=¬∂.+)\b\S+\b(?=.+¬∂)
```
[Try it online!](https://tio.run/##K0otycxLNPz/X8PexvbQNj1tzZikmGDtmCQNe1s97UPbNLn@/7dUMFLQNVUw5jK0UDBWsFAw4DJSMFcwMlTQNeayBMkYGihYWgIA "Retina ‚Äì Try It Online")
Expects a matrix as having columns separated by spaces and rows separated by newlines. Works by removing numbers that have a newline more than immediately before and after them. The boundaries are required to avoid deleting digits/signs elsewhere in the boundary numbers since there isn't a way to make lookahead/behind non-greedy/backtrack (at least in fewer than 4 bytes).
Seems shorter than [listing all boundary](https://tio.run/##K0otycxLNPz/3ychTk@7Rk9bpSYmWFvD3vbQNs0aDXsbEA0U@P/fUsFIQddUwZjL0ELBWMFCwYDLSMFcwchQQdeYyxIkY2igYGkJAA) numbers, for the same reason. I've found a [slightly crazy](https://tio.run/##K0otycxLNPz/3ychTk@7Rk9bpSamXPvQtpoY9@g4nVjt//8tdYx04k11jLkMLXSMdSx0DLiMdMx1jAx14o25LEEyhgY6lpYA) version that is a byte shorter, but is also far more abusive of the lax I/O.
```
L`^.+|.+$|\w+¬∂|\G[^,]+
```
[Answer]
# [Ruby](https://www.ruby-lang.org/), ~~31~~ 29 bytes
Very similar to [SuperStormer‚Äôs Python 3 answer](https://codegolf.stackexchange.com/a/260991/11261). Outputs by modifying the given array.
```
->a{a[r=1..-2].map{_1[r]=[]}}
```
[Attempt This Online!](https://ato.pxeger.com/run?1=XY9NDoIwEIX3nGIO8EpoFSkxdcklJhNTE92ZGISFIZzEDTF6DPdewdtY6AbczN_73kzm_qzbw214VO7VNidl32rnO8-102mqjKRnf-n2mmtxLH0fme-nOV4bcjSyVLGXLXnqk-RCo8DMGgYrQUK8Ro7NVBWwKEVkhmXLlkqQgcpB0attqEAhZlMfRCpgNFTUAx9gnaH82xvPL0bl5LCzOHriP8MQ8w8)
]