[erlang-questions] Matrix rotator
Sun Jun 14 22:01:04 CEST 2009
Tony Arcieri wrote:
> I saw a fairly interesting problem posted on this week's Ruby Quiz, a matrix
> I thought this problem might also be interesting to an Erlang audience as
> The goal is to rotate an arbitrary sized input matrix 90 degrees
I don't have the time right now, but this function could serve as an
inspiration: it doesn't quite do what you want - it transposes rather
than rotates the matrix:
%% Transpose rows and columns in a list of lists. Works even if
%% sublists are not of same length. Empty sublists are stripped.
transpose() -> ;
transpose([ | Xss]) -> transpose(Xss);
transpose([[X | Xs] | Xss]) ->
[[X | [H || [H | T] <- Xss]]
| transpose([Xs | [T || [H | T] <- Xss]])].
I think I stole it from the Haskell standard library.
More information about the erlang-questions