A quarter turn
Turn a picture a quarter turn clockwise, the way your phone does when you tip it.
Write rotate(matrix): matrix is n rows of n numbers. Return a new matrix turned 90 degrees clockwise, so the first column read from bottom to top becomes the first row.
Call show(m) after each step (each swap or each row you finish) and the stage draws the picture as it turns.
Example: rotate([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) returns [[7, 4, 1], [8, 5, 2], [9, 6, 3]].
Tests you can see
rotate([[1,2,3],[4,5,6],[7,8,9]])[[7,4,1],[8,5,2],[9,6,3]]rotate([[1,0,0],[1,0,0],[1,1,1]])[[1,1,1],[1,0,0],[1,0,0]]
More tests are hidden. The server runs them all before a time counts.
Call show() while your code works and the run plays back here.
javascriptrotate()
Tab indents · Cmd/Ctrl+Enter runs