[erlang-questions] Matrix rotator
Johnny Billquist
bqt@REDACTED
Sun Jun 14 22:08:04 CEST 2009
The problem is rather trivial in itself. Are you looking for some
particularly efficient algorithm, or what?
Johnny
Tony Arcieri wrote:
> 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?
>
--
Johnny Billquist || "I'm on a bus
|| on a psychedelic trip
email: bqt@REDACTED || Reading murder books
pdp is alive! || tryin' to stay hip" - B. Idol
More information about the erlang-questions
mailing list