[Question]
  [
The title pretty much describes it all. Given as input a \$n \times m\$ matrix and an integer \$i\$ create a complete function/program that returns the matrix \$i\$ times clockwise rotated by \$90^\circ\$.
**Rules:**
* as matrix you can use any convenient representation you like e.g. *a list of lists etc...*
* matrix values can be positive and/or negative integer numbers
* \$n\$ and \$m\$ are of course always positive integers between 1 and 10
* \$i\$ can be any valid integer which belongs in the following range: \${0...10^5}\$
* Standard [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'") rules & winning criteria apply but no "winning" answer will be chosen.
**EDIT:** I had to edit the initial question because for some programming languages it takes too long to compute the result for \$i\in\{0...10^7\}\$. There is a workaround to it but since it's a code-golf just make sure that it simply runs successfully for at least \$i\in\{0...10^5\}\$.
**Some test cases:**
```
==== example 1 ====
Input:
5
[[1, 3, 2, 30,],
 [4, 9, 7, 10,],
 [6, 8, 5, 25 ]]
Expected Output:
[[ 6  4  1],
 [ 8  9  3],
 [ 5  7  2],
 [25 10 30]]
==== example 2 ====
Input:
100
[[1]]
Expected Output:
[[1]]
==== example 3 ====
Input:
15
[[150,    3,  2],
 [  4, -940,  7],
 [  6, 8000,  5]]
Expected Output:
[[   2    7    5],
 [   3 -940 8000],
 [ 150    4    6]]
==== example 4 ====
Input:
40001
[[1, 3, 9]]
Expected Output:
[[1],
 [3],
 [9]]
```
```
  
[Answer]
# [APL (Dyalog Unicode)](https://www.dyalog.com/), 7 bytes
```
⌽∘⍉⍣⎕⊢⎕
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT///qKO94P@jnr2POmY86u181Lv4Ud/UR12LgCRI6r8CGBRwPWqbCBTyCvb3U1CPjjbUUTDWUTACkgaxOgrRJjoKljoK5joKhmCumY6ChY6CKVCBqUJsrDqXKRcOU0CShgYGWKRBsqYGOiBhoEUKRiBjFRSA9uhamoCEzSECIJsMDEACpmCzTHEYBXauJUiJiQEIGAIA "APL (Dyalog Unicode) – Try It Online")
`⎕` prompt for matrix expression from stdin
`⊢` yield that
`⎕` prompt for \$i\$ expression from stdin
`⍣` do the following that many times
`⍉` transpose
`∘` and then
`⌽` mirror
[Answer]
# [J](http://jsoftware.com/), 7 bytes
```
|:@|.^:
```
[Try it online!](https://tio.run/##y/qvpKeepmBrpaCuoKNgoGAFxLp6Cs5BPm7/a6wcavTirP5rcqUmZ@QrZOoZK5hAmOq6urrqEKaBQhoOGUOcMkY4ZYxxm2ZgALfqPwA "J – Try It Online")
An adverb train. Right argument is the matrix, left argument is the repetition count.
### How it works
```
|:@|.^:
     ^:  Repeat the function:
   |.      Reverse vertically
  @        and then
|:         Transpose
         Absent right argument to `^:`:
           bind to the left argument (repeat count)
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 4 bytes
Naive implementation. There might be a shorter way I'm not aware of.
```
ṚZ$¡
```
[Try it online!](https://tio.run/##y0rNyan8///hzllRKocW/j/c7v2oaU3k///R0YamBjoKQGAMJI1idbgUohUUTHQUdC1NQOLmUBEzHQULAwOQiGls7H9DUwA "Jelly – Try It Online")
[Answer]
# [Haskell](https://www.haskell.org/), 50 bytes
```
(!!).iterate(foldr(zipWith$flip(++).pure)e)
e=[]:e
```
[Try it online!](https://tio.run/##dYw5DsIwFAX7nOJFSmErn4gtbFLOQWFcWOGbWJhgOabh8Jj0iCmmGs1gpjt7n213yaIsZeMSR5NY2Ke/RvF24ezSUFnvgqhr2YRXZMmy4E7pE@eHcSM6hOjGhAoWSq0IG8J69lJTgR/UlnAk7AmrP8GOcCC086TVGm3@9Nab25QXfQhf "Haskell – Try It Online")
[Answer]
# [Ruby](https://www.ruby-lang.org/), 39 bytes
```
->m,n{n.times{m=m.reverse.transpose};m}
```
[Try it online!](https://tio.run/##KypNqvyfZvtf1y5XJ686T68kMze1uDrXNlevKLUstag4Va@kKDGvuCC/OLXWOrf2f4FCmkJ0dLShjoKxjoIRkDSI1VGINtFRsNRRMNdRMARzzXQULHQUTIEKTGOBfNPY/wA "Ruby – Try It Online")
[Answer]
# [K (oK)](https://github.com/JohnEarnest/ok), 6 bytes
```
(+|:)/
```
[Try it online!](https://tio.run/##Hcu7EYAwDIPhVdQRHy8nJITE@9BQsAC7G0H33@nTNd@X@9nD@HRZ/VyGEIqFiA0JmxoyGioia8eBglREuKvaFL/4cFFyJAP13LIC1ahVWT/PzMgDWRPxFw "K (oK) – Try It Online")
[Answer]
# [Pyth](https://github.com/isaacg1/pyth), 7 6 bytes
```
uC_GQE
```
[Try it online!](https://tio.run/##K6gsyfj/v9Q53j3Q9f9/U67oaEMdBWMdBSMgaRCrE22io2Cpo2Cuo2AI4pnpKFjoKJgCpU0VYmMB "Pyth – Try It Online")
-1 Thanks to @FryAmTheEggman
Rotates the matrix by reversing the order of rows and taking the transpose. Takes and returns lists of lists.
## How it works
```
uC_GQE
u    E - Reduce the second input
  _G   - By reversing the order of rows
 C     - And transposing
    Q  - An amount of times equal to the first input  
```
[Answer]
# [Japt](https://github.com/ETHproductions/japt) [`-R`](https://codegolf.meta.stackexchange.com/a/14339/), 2 [bytes](https://en.wikipedia.org/wiki/ISO/IEC_8859-1)
```
zV
```
[Try it](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&flags=LVI&code=elY&input=W1sgMSwgMiwgMywgNF0sCiBbMTEsMTIsMTMsMTRdLAogWzIxLDIyLDIzLDI0XQpdCjM)
```
Rotate matrix by 90 degrees 2nd input times
```
[Answer]
# [Python 2](https://docs.python.org/2/), 44 bytes
```
f=lambda A,i:i%4and f(zip(*A[::-1]),i-1)or A
```
[Try it online!](https://tio.run/##bY/BboMwEETP9VfMpbLdLBVOoClEHLjkJywOVIDqihjkEintz1ObQg5VfbB2x/Nm1@PX9D7Y/Tx3RV9f3poaJZncPCa1bdCJbzOKp1LneaQqSSZScnAo56btcBbeKXOGsrjUo5iuY99SKRlGZ@yEksEV3eJhMB361goni0Llv@@fk/P9aWlOrp2uzm4o14LvOPHnj8FYEcK9mZyOKyl3XBJn6PwaNxgLp1XYLWcPC8uxoPjD3u7gOgH/Twi/DM5qczJ2FlorwoGw93dMFTHohJARjgS1Ci@EV0LqTSmqilK5gr5WW53GBH98EvYLBPicKEuCflyVEBTHQUkDew9aNsi8hMQ/Kzn/AA "Python 2 – Try It Online")
Input/output is a `list` of `tuples`. (The `%4` is a workaround for Python's recursion limit; could save a byte otherwise).
[Answer]
# [05AB1E (legacy)](https://github.com/Adriandmen/05AB1E/wiki/Commands), 3 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
Føí
```
Takes \$i\$ as first input; matrix the second.
[Try it online](https://tio.run/##MzBNTDJM/f/f7fCOw2v//zflio421DHWMdIxNojViTbRsdQx1zEEMc10LHRMdYxMY2MB) or [verify all test cases](https://tio.run/##MzBNTDJM/W/ipuSZV1BaUmyloGTv6WKvpJCYlwJi2hZzKfmXlgClQDL/3Q7vOLz2f63OoW32/025oqMNdYx1jHSMDWJ1ok10LHXMdQxBTDMdCx1THSPT2FguQwMDkDIQC6ze1ACkA6xc19LEQMccotzAwEAHpNwEyDCEmmsZGwsA).
**Explanation:**
```
F    # Loop the (implicit) input-integer amount of times:
 ø   #  Zip/transpose the matrix; swapping rows/columns
     #  (this will take the (implicit) input in the first iteration)
  í  #  Reverse each row
     # (after the loop, the resulting matrix is output implicitly)
```
NOTE: Uses the legacy version only because of performance. [The last test case times out in the rewrite version.](https://tio.run/##yy9OTMpM/f/f7fCOw2v//zcxMDAw5IqONtQx1rGMjQUA) Both the legacy and rewrite versions would be the same, though.
[Answer]
# [Julia 1.0](http://julialang.org/), 6 bytes
Kind of cheating, but Julia has a built in `rotl90` function, that does exactly that.
```
rotl90
```
[Try it online!](https://tio.run/##Vc3PCsIwDAbwe5/iOzYw4cvWOnsQfI/hwUtxUhj4h/n2Nd1BFBIIyccvt1eZL/qu@Vjvy7MkVnd6XJfVZz9BMaDHQIeAhBFq0x4HRPQR5w5RxH3jeS7Fa4dWYk3@Xg2LbFyzdikQ42aRxGbpHza118nWwQIqUj8 "Julia 1.0 – Try It Online")
[Answer]
# JavaScript (ES6), 58 bytes
Takes input as `(i)(matrix)`.
```
i=>g=m=>i--?g(m[0].map((_,x)=>m.map(r=>r[x]).reverse())):m
```
[Try it online!](https://tio.run/##bY7BCoMwEETvfsUeE1hltabWQuyHSChio1iMSizi39tosSC4h4WdGd7su5iKsbTN8PG7/qWXSi6NzGppZNb4/qNmJicVmGJg7Ikzl5nZDiszm8@KB1ZP2o6acc7vZin7buxbHbR9zSomOMs9gDxEuCBEbhMqXJUYIUVIEMJduSLcEISLCVCe4tw7skKinXZq/7sEIbhxhRD90ACuzk/j1Uh2ae0jWiVxxouJwsP36ZZavg "JavaScript (Node.js) – Try It Online")
**Note**: The last test case was edited to prevent a recursion error. We can obviously use [`i--&3`](https://tio.run/##bY7NCoMwEITvPsWeSgKrxJ/UWoh9EAlFbBSLMRKL@PY2WiwI7mFhZ4b59l1O5VjZdvj4vXmppRZLK/JGaJG3vn@JHw3RBZOBLgdCnjhTkevtsCK3xSxpYNWk7KgIpfSul8r0o@lU0JmG1IRTUngARYgQI0RuM5S4KglChpAihLtyRbghcBfjID1JqXfsChnb207tP4szBDcOCNGvGsDh/CxZjXSXVh5jq8TP@hLnhYf3sy22fAE) (60 bytes) to support much larger values.
[Answer]
# [Octave](https://www.gnu.org/software/octave/), 17 bytes
Unfortunately `rot90` rotates the input *counterclockwise*.
```
@(x,i)rot90(x,-i)
```
[Try it online!](https://tio.run/##y08uSSxL/Z9mq6en999Bo0InU7Mov8TSAMjSzdT8b82Vq2CrEG2oY2RtrGMSa82VkllcoJGrCWWo6wKBuiaEk6aRq6NgqKlp/R8A "Octave – Try It Online")
[Answer]
# [MATL](https://github.com/lmendo/MATL), ~~5~~ 3 bytes
-2 bytes thanks to @LuisMendo!
```
_X!
```
[Try it online!](https://tio.run/##y00syfn/Pz5C8f9/I65oQx0ja2Mdk1gA "MATL – Try It Online")
[Answer]
# Java 8, ~~141~~ ~~138~~ ~~131~~ 130 bytes
```
(m,i)->{for(int t[][],a,b,j;i-->0;m=t)for(t=new int[b=m[0].length][a=m.length],j=a*b;j-->0;)t[j%b][j/b]=m[a-j/b-1][j%b];return m;}
```
-7 bytes thanks to *@OlivierGrégoire*.
[Try it online.](https://tio.run/##hZJNT4NAEIbv/opJExPQgS7aqi2hiUcP6kFvhMNC17oI2wYGP0L47XVYWi/ayoHM7rwz88zs5PJdevnybZsVsq7hXmrTngBoQ6p6kZmCh/5oL@IkTiBz9laJbIF2Q/Z3J/yrSZLO4AEMRLB12O96i/ZlXfUhYINQYop5qD1vIcIyIrf3UmTUhy2QRmUsEr9QZkWvSSyjcm9jHsmzNMxtoEtxfpomcT5OE45g/nHqBYm9DCtFTWWgDLtt2FNtmrRgqh3c@1ovoeQmnSeqtFlxH9IdOiRVk7MnYda2DfASL/BSdGgFv752gjO8xuCw4ApvcIoX065DmNpJ/VmndwdCHBZMBbKDaQ5WApigN5sIvD4iYRwhBFqc4AgP9z3rNRNWB78e2M7QRv2sguRhfiIMCzGM8@mrJlX664b8DU@aCuOM7symoXoOo3N9PgJplmzlvIB@Q7rwb6tKftX@UqnN83p4HmfI7O5Q/8r52BAnnf@byfiZ88PpHsm467fbfgM)
**Code explanation:**
```
(m,i)->{                 // Method with int-matrix and int parameters and int-matrix return
  for(int t[][],         //  Temp int-matrix as replacement
          a,b,           //  Temp integers used for the dimensions
          j;             //  Temp integer for the inner loop
      i-->0;             //  Loop the input `i` amount of times:
      m=t)               //    After every iteration: replace the input-matrix `m` with `t`
    for(t=new int[b=m[0].length][a=m.length],
                         //   Create a new temp-matrix `t` with dimensions `b` by `a`,
                         //   where `b` & `a` are the amount of columns & rows of matrix `m`
        j=a*b;           //   Set `j` to the product of these dimensions
        j-->0;)          //   And inner loop in the range [`j`, 0):
      t                  //  Replace the value in `t` at position:
       [j%b]             //   `j%b` (let's call this row A),
            [j/b]        //   `j/b` (let's call this column B)
        =m               //  And replace it with the value in `m` at position:
          [a-j/b-1]      //   `a-j/b-1` (which is the reversed column B as row,
                         //     so it both transposes and reverses at the same time),
                   [j%b];//   `j%b` (which is row A as column)
  return m;}             //  And finally return the new int-matrix
```
**To save bytes**, the inner loop is a single loop and uses `j/a` and `j%a` as cell positions. So a loop like this:
```
for(r=a;r-->0;)for(c=b;c-->0;)t[c][r]=m[b-r-1][c];
```
Has been golfed to this:
```
for(j=a*b;j-->0;)t[j%b][j/b]=m[a-j/b-1][j%b];
```
to save 5 bytes.
[Answer]
# [R](https://www.r-project.org/), 64 bytes
```
r=function(x,i){o=x;n=0;while(n<i){o=t(apply(o,2,rev));n=n+1};o}
```
[Try it online!](https://tio.run/##VYxNCsIwFIT3PcVbvoezSFqrlphbeIFaKgZqUkLtD9Kzx@pCcDPwzTdMTCna29M3gwueZzh5BTsbb5WZ7q5r2Z@/1cB133cLB@SI7SiyTfxOryasabSPeohu5oY1qADlWypktAdVoCNIf@gAOoHKTZeCAtclhsleJIs8opTs96Kh/6VWStIb "R – Try It Online")
Not really efficient...
Uses rotation approach proposed by [Matthew Lundberg](https://stackoverflow.com/questions/16496210/rotate-a-matrix-in-r)
[Answer]
# [Husk](https://github.com/barbuz/Husk), 7 bytes
```
~!→¡oT↔
```
[Try it online!](https://tio.run/##yygtzv6f6/aoqfF/neKjtkmHFuaHPGqb8v///2gNU53oaEMdYx0jHWODWJ1oEx1LHXMdQxDTTMdCx1THyDQ2VlNHw9DAAKQQwgbrMTUA6QJr0bU0MdAxh2gxACoEaYkFAA "Husk – Try It Online") I've always found it odd that the only real way to iterate a function a set number of times in Husk is to index into the infinite list of that function's iterates.
[Answer]
# [Pari/GP](http://pari.math.u-bordeaux.fr/), 37 bytes
```
f(m,n)=for(i=1,n,m=Mat(Vecrev(m~)));m
```
[Try it online!](https://tio.run/##PY3PCoMwDIdfJXhqIULjdJuIe4Nddyk9BNEhWFeKDHbZq3fpHDvkz4@PLwkc5/IeUpqUx1X30yOquSdc0fdX3tRtHOL4VP6tte584hCWl2IoLxDivG6KLTkoEApgW8mWSQEDL4uaEFhrBGstIRwQKummgxqhRTghkIQjwhmhEdg4mVI2vyWdscnRUmN2/auWbS3xtJvGmF2iv/n71Tq5UAsn53T6AA "Pari/GP – Try It Online")
[Answer]
# [GolfScript](http://www.golfscript.com/golfscript/), 10 bytes
```
~{-1%zip}*
```
[Try it online!](https://tio.run/##S8/PSStOLsosKPn/v65a11C1KrOgVuv//@hoQwVjBSMFY4NYhWgTBUsFcwVDENNMwULBVMHINDZWwRQA "GolfScript – Try It Online")
```
~{      }*   # Repeat i times
  -1%        # Reverse the array
     zip     # Zip
```
When the program finishes, only the elements of the matrix are displayed. To see how it actually was outputted, use [this](https://tio.run/##S8/PSStOLsosKPn/v65a11C1KrOgVivh///oaEMFYwUjBWODWIVoEwVLBXMFQxDTTMFCwVTByDQ2VsEUAA "GolfScript – Try It Online").
[Answer]
# [Arn](https://github.com/ZippyMagician/Arn), [~~8~~ 7 bytes](https://github.com/ZippyMagician/Arn/wiki/Carn)
```
Ç├Úe↑Î(
```
[Try it!](https://zippymagician.github.io/Arn?code=Ji57LkBALjw=&input=W1sxIDMgOV1dIFtOXSA0MDAwMQpbWzFdXSBbTl0gMTAwCltbMTUwIDMgMl0gWzQgXzk0MCA3XSBbNiA4MDAwIDVdXSBbTl0gMTU=&flags=ZQ==)
# Explained
Unpacked: `&.{.@@.<`
ELABORATE HERE
```
&. Mutate N times
  { Block, key of `_`
        _ Implied variable
      .@ Transposed
    @ Binded map
      .< Reverse
  } End block; implied
```
Input is two lines, the first being an array and the second a number. `&.` supports both 2 separate inputs and one as an array, and as `_` is automatically the STDIN separated on newlines and parsed, this code is valid.
[Answer]
# Mathematica, 32 bytes
```
a = {{3, 4, 5}, {5, 6, 7}, {8, 9, 10}, {11, 12, 13}};
Nest[Reverse /@ Transpose[#] &, a, i] 
```
]