Matrix rotator
Tony Arcieri
tony@REDACTED
Sun Jun 14 21:29:36 CEST 2009
I saw a fairly interesting problem posted on this week's Ruby Quiz, a matrix
rotator:
http://osdir.com/ml/ruby-talk/2009-06/msg01127.html
I thought this problem might also be interesting to an Erlang audience as
well.
The goal is to rotate an arbitrary sized input matrix 90 degrees
counterclockwise, e.g.:
0 0 0 0
0 X 0 0
X X X 0
0 0 0 0
0 0 0 0
0 0 X 0
0 X X 0
0 0 X 0
If you were to represent the matrix as nested lists, then an input of:
[[0, 1, 0, 0],
[0, 1, 1, 0],
[0, 0, 1, 0],
[0, 0, 0, 0]]
would produce an output of:
[[0, 0, 0, 0],
[0, 1, 1, 0],
[1, 1, 0, 0],
[0, 0, 0, 0]]
In the rectangular case, an input:
[[0, 1, 0],
[1, 1, 1]]
produces an output:
[[0, 1],
[1, 1],
[0, 1]]
Any takers?
--
Tony Arcieri
More information about the erlang-questions
mailing list