Skip to content

Instantly share code, notes, and snippets.

@bortels
Created July 1, 2014 06:54
Show Gist options
  • Save bortels/03691d013f2b394055fd to your computer and use it in GitHub Desktop.
Save bortels/03691d013f2b394055fd to your computer and use it in GitHub Desktop.
stuff I should have remembered from school
The below is ruby(ish) - but is really about matrix math
array.transpose flips array around diagonal axis (UL to LR):
a = [[1, 2, 3],
[4, 5, 6],
[7, 8, 9]]
a.transpose => [[1, 4, 7],
[2, 5, 8],
[3, 6, 9]]
if you transpose then reverse - you've rotated the array CCW 90 degrees:
a.t.reverse => [[3, 6, 9],
[2, 5, 8],
[1, 4, 7]]
Repeat that 4 times, you're back to where you started.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment