Question: I have a single coordinate, say `{ x: 1, y: 2 }` and a matrix size `{ x: 5, y: 6 }`. I would like to rotate that single coordinate around the grid by 90 degrees (clockwise). I can rotate an entire grid by running:

```js
function rotate90(a){
  // transpose from http://www.codesuck.com/2012/02/transpose-javascript-array-in-one-line.html
  a = Object.keys(a[0]).map(function (c) { return a.map(function (r) { return r[c]; }); });
  // row reverse
  for (i in a){
    a[i] = a[i].reverse();
  }
  return a;
}

```

Which takes a grid from:

```
[1][2][3][4]
[5][6][7][8]
[9][0][1][2]
[3][4][5][6]

```

to

```
[3][9][5][1]
[4][0][6][2]
[5][1][7][3]
[6][2][8][4]

```

How can I do the same with a single coordinate? Some examples on a 4 x 4 grid might be:

```
0, 0 -> 0, 3
0, 3 -> 3, 3
3, 3 -> 3, 0
3, 0 -> 0, 0

1, 1 -> 1, 2
1, 2 -> 2, 2
2, 2 -> 2, 1
2, 1 -> 1, 1

```

Answer: 
Starting with a MxN array, (x,y) -> (y,M-x-1)
I used a rotate function inside of a Class when I wrote Tetris.

```
def rotate(self):
    self.rotation = (self.rotation + 1) % len(self.figures[self.type])

```

I had a list of figures with the rotations in a matrix, the only thing is rather than going to 0 after 9, I continued on with 10.

```
figures = [
    [[8, 9, 10, 11], [2, 6, 10, 14], [11, 10, 9, 8], [13, 9, 5, 1]], #0
    [[4, 8, 9, 10], [6, 5, 9, 13], [14, 10, 9, 8], [12, 13, 9, 5]],  #1
    [[6, 8, 9, 10], [14, 5, 9, 13], [12, 10, 9, 8], [4, 5, 9, 13]],  #2
    [[5, 6, 10, 9], [5, 6, 10, 9], [5, 6, 10, 9], [5, 6, 10, 9]],    #3
    [[5, 6, 9, 8], [10, 14, 9, 5], [13, 12, 9, 10], [8, 4, 9, 13]],  #4
    [[4, 5, 9, 10], [6, 10, 9, 13], [14, 13, 9, 8], [12, 8, 9, 5]],  #5
    [[5, 8, 9, 10], [5, 10, 9, 13], [13, 10, 9, 8], [8, 13, 9, 5]],  #6
]

```

Since I had multiple figures, I had them selected by random, but you can make it controlled as well

```
self.type = random.randint(0, len(self.figures) - 1)

```