For those of us who didn't know Matrix was built in, my first crack at it
was...
irb(main):011:0> a = [[1,2],[3,4],[5,6]]
[[1, 2], [3, 4], [5, 6]]
irb(main):012:0> c = []; a[0].size.times{c.push([])}; a.each{|b| bi = 0;
b.each
{|b1| c[bi].push(b1); bi += 1}}; c
[[1, 3, 5], [2, 4, 6]]
-----Original Message-----
From: Daniel Bretoi [mailto:lists / debonair.net]
Sent: Wednesday, July 31, 2002 11:24 AM
To: ruby-talk ML
Subject: matrix challange
Hi all,
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 haven't had time to do a solution myself, but I think it would be
interesting to see how some of you guys would tackle it while I
derive something.
--
"Then we typed the G, and the system crashed"...