Rotate Square Matrix Clockwise, In Place.
Description:
Given a square matrix, rotate it 90 degrees to the right.
For example, given:
[
['a','b'],
['c','d']
]
return:
[
['c','a'],
['d','b']
]
And given:
[
['a','b','c','d'],
['e','f','g','h'],
['i','j','k','l'],
['m','n','o','p'],
]
return:
[
['m','i','d','a'],
['n','j','f','b'],
['o','k','g','c'],
['p','l','h','d'],
]
This is an honor-system Kata. There's only so much I can do to enforce that you use an in-place algorithm. If you cheat and move more than one value at a time you'll feel like a dirty, dirty cheater, so hopefully that's enough.
You can call stringify
to get a loggable representation of your progress if you'd like. eg: console.log(stringify(sq))
.
If you're lucky enough to be discoving a matrix rotation for the first time, do yourself a favor and don't google it. It can be figured out from scratch and it's incredibly rewarding, though time-consuming, to do so.
Also, I'll warn you, this is an off-by-one minefield.
Good luck, have fun!
Similar Kata:
Stats:
Created | Oct 7, 2016 |
Warriors Trained | 80 |
Total Skips | 0 |
Total Code Submissions | 108 |
Total Times Completed | 26 |
JavaScript Completions | 26 |
Total Stars | 3 |
% of votes with a positive feedback rating | 75% of 12 |
Total "Very Satisfied" Votes | 8 |
Total "Somewhat Satisfied" Votes | 2 |
Total "Not Satisfied" Votes | 2 |
Total Rank Assessments | 10 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 5 kyu |
Lowest Assessed Rank | 8 kyu |