From: Paul Brannan Date: 2002-08-01T01:29:48+09:00 Subject: Re: matrix challange On Thu, Aug 01, 2002 at 01:23:41AM +0900, Daniel Bretoi wrote: > I'd like to see the various solutions for coming up with code to > transpose a matrix. ie. make > > a = [[1,2],[1,3],[2,4]] > > look like > > aT = [[1,1,2],[2,3,4]] I would do this: irb(main):001:0> require 'matrix' true irb(main):002:0> a = [[1,2],[1,3],[2,4]] [[1, 2], [1, 3], [2, 4]] irb(main):003:0> aT = Matrix[*a].transpose.to_a [[1, 1, 2], [2, 3, 4]] Paul