2021-12-04 15:50:34 +01:00
|
|
|
# rotate-2-dimensional-array-90-degrees
|
|
|
|
|
2023-07-02 17:28:54 +02:00
|
|
|
Created by [@theoludwig](https://github.com/theoludwig) on 3 December 2021.
|
2021-12-04 15:50:34 +01:00
|
|
|
|
|
|
|
## Instructions
|
|
|
|
|
|
|
|
Given a square/rectangle matrix representing an image and a direction of rotation (`clockwise` or `anticlockwise`), rotate the image by 90 degrees.
|
|
|
|
|
|
|
|
### Input
|
|
|
|
|
|
|
|
- **Line 1:** The direction (`clockwise` or `anticlockwise`) of rotation
|
|
|
|
- **Next Lines:** The matrix of the image
|
|
|
|
|
|
|
|
### Output
|
|
|
|
|
|
|
|
- **Lines:** The rotated matrix
|
|
|
|
|
|
|
|
## Examples
|
|
|
|
|
|
|
|
### Example 1
|
|
|
|
|
|
|
|
#### Input
|
|
|
|
|
|
|
|
```txt
|
|
|
|
clockwise
|
|
|
|
1 2 3
|
|
|
|
4 5 6
|
|
|
|
7 8 9
|
|
|
|
```
|
|
|
|
|
|
|
|
#### Output
|
|
|
|
|
|
|
|
```txt
|
|
|
|
7 4 1
|
|
|
|
8 5 2
|
|
|
|
9 6 3
|
|
|
|
```
|
|
|
|
|
|
|
|
### Example 2
|
|
|
|
|
|
|
|
#### Input
|
|
|
|
|
|
|
|
```txt
|
|
|
|
anticlockwise
|
|
|
|
1 2 3
|
|
|
|
4 5 6
|
|
|
|
7 8 9
|
|
|
|
```
|
|
|
|
|
|
|
|
#### Output
|
|
|
|
|
|
|
|
```txt
|
|
|
|
1 4 7
|
|
|
|
2 5 8
|
|
|
|
3 6 9
|
|
|
|
```
|
|
|
|
|
|
|
|
See the `test` folder for examples of input/output.
|