On Thu, Sep 11, 2008 at 2:02 PM, Peter Bunyan <peter.bunyan / gmail.com> wrote: > Patrick Doyle wrote: >> There has got to be a more elegant solution than this. Suppose I have >> 2 identical length arrays that I want to add together to produce a >> third array. The best solution I've come up with is: >> >> c = (0...a.size).map {|i| a[i] + b[i]} >> >> Any suggestions? >> >> --wpd > > http://www.ruby-doc.org/stdlib/libdoc/matrix/rdoc/classes/Matrix.html Yeah, that's probably what I would do for a simple script. I haven't checked memory usage, but it is elegant IMHO. Probably best for very large arrays. a = 1, 2, 3, 4 b = 4, 3, 2, 1 (Matrix[a] + Matrix[b]).to_a.flatten => [5, 5, 5, 5] Todd