Matrix Rotation

Generate and rotate by 90

Matrix Rotate 90 Degrees Counter-Clockwise

Problem Statement

Given a 4×4 square matrix filled with random integers (0-99), rotate the matrix 90 degrees counter-clockwise and store the result in a new matrix.

A 90-degree counter-clockwise rotation transforms the matrix such that:

  • The first column becomes the last row (reversed)
  • The second column becomes the third row (reversed)
  • And so on...

Your task is to write constraints to generate a matrix and its 90-degree counter-clockwise rotated version that satisfy the rotation constraint.

Constraints

  • Matrix size: 4×4
  • Each element: 0 ≤ element ≤ 99
  • Rotated matrix must correctly represent a 90° counter-clockwise rotation
  • Relationship: rotatedi = originalj

Examples

Example 1:

Original:
 1  2  3  4
 5  6  7  8
 9 10 11 12
13 14 15 16

Rotated (90° CCW):
 4  8 12 16
 3  7 11 15
 2  6 10 14
 1  5  9 13

Explanation: The rightmost column (4,8,12,16) becomes the top row. The leftmost column (1,5,9,13) becomes the bottom row.

Example 2:

Original:
10 20 30 40
50 60 70 80
11 12 13 14
15 16 17 18

Rotated (90° CCW):
40 80 14 18
30 70 13 17
20 60 12 16
10 50 11 15

Explanation: Each column from left to right becomes a row from bottom to top.

Example 3:

Original:
 1  1  1  1
 2  2  2  2
 3  3  3  3
 4  4  4  4

Rotated (90° CCW):
 1  2  3  4
 1  2  3  4
 1  2  3  4
 1  2  3  4

Explanation: When all values in a row are the same, the rotated matrix shows these values in columns.

Loading the interactive workspace...