From: Rolf Pedersen Date: 2010-04-25T23:08:36+09:00 Subject: Re: Populate (an array or a matrix) from a vector --00163630e883b3edfd04851016d7 Content-Type: text/plain; charset=ISO-8859-1 Tip: Did you check out the Matrix and Vector classes in the Ruby Standard Library? http://ruby-doc.org/core/classes/Matrix.html http://ruby-doc.org/core/classes/Vector.html Best regards, -Rolf On Sun, Apr 25, 2010 at 3:10 PM, Paul A. wrote: > Hello, > > I have a simple, but very tricky, problem. I would like to fix it using > an array. But matix are possibly more appropriate (even if matrix can > not have 3 dimensional values, I think). > > I would like to populate a table (of 2 or 3 dimensions), from a vector. > > I think the best way to explain myself is to put some examples, with an > array such as: > > >> # thanks to Rolf Pedersen's function ( > http://www.ruby-forum.com/topic/208620) > >> table = make_array(3, 5) > > And now, if the seeder vector is: [1, 0], the result should be: > > => [ > => [4, 3, 2, 1, 0], > => [4, 3, 2, 1, 0], > => [4, 3, 2, 1, 0] > => ] > > If the vector is: [-1, 0] > > => [ > => [0, 1, 2, 3, 4], > => [0, 1, 2, 3, 4], > => [0, 1, 2, 3, 4] > => ] > > If the vector is: [-2, 0] > > => [ > => [0, 0, 1, 1, 2], > => [0, 0, 1, 1, 2], > => [0, 0, 1, 1, 2] > => ] > > If the vector is: [1, 1] > > => [ > => [2, 2, 2, 1, 0], > => [1, 1, 1, 1, 0], > => [0, 0, 0, 0, 0] > => ] > > If the vector is: [0, 1] > > => [ > => [2, 2, 2, 2, 2], > => [1, 1, 1, 1, 1], > => [0, 0, 0, 0, 0] > => ] > > Have you got a idea, or a plan? :s > Any comments are welcome. Thank you. > > Best regards. > -- > Posted via http://www.ruby-forum.com/. > > --00163630e883b3edfd04851016d7--