How can i get that kind of transpose?

there is text1
1,2,3,4
1,2,3
1,2
1,2,3,4,5
what i want to get is text2:
1,1,1,1
2,2,2,2
3,3, 3
4, 4
5
how to get it ?

On Sat, May 1, 2010 at 8:59 PM, Pen T. [email protected] wrote:

5
how to get it ?

Try googling for ruby matrix rotate.

http://snippets.dzone.com/tag/rotate came up in a 2 second search.

This is also a ruby quiz.
http://rubyquiz.strd6.com/quizzes/209-matrix-rotator

Andrew McElroy

On Sun, May 2, 2010 at 9:59 AM, Pen T. [email protected] wrote:

there is text1
1,2,3,4
1,2,3
1,2
1,2,3,4,5$
what i want to get is text2:
1,1,1,1
2,2,2,2
3,3,  3>> Matrix[[1,2,3,4], [1,2,3], [1,2]]. transpose
=> Matrix[[1, 1, 1], [2, 2, 2], [3, 3, nil], [4, nil, nil]]

4,  4
5
how to get it ?

search for it first,

$ qri transpose

------------------------------------------------------ Multiple choices:

 Array#transpose, Matrix#transpose

so eg,

=> Matrix[[1, 3, 5], [2, 4, 6]]

Matrix[[1,2,3,4], [1,2,3], [1,2]]. transpose
=> Matrix[[1, 1, 1], [2, 2, 2], [3, 3, nil], [4, nil, nil]]

kind regards -botp

Pen T. wrote:

there is text1
1,2,3,4
1,2,3
1,2
1,2,3,4,5
what i want to get is text2:
1,1,1,1
2,2,2,2
3,3, 3
4, 4
5

Is this what you want?

a = [[1,2,3,4,nil],[1,2,3,nil,nil],[1,2,nil,nil,nil],[1,2,3,4,5]]
=> [[1, 2, 3, 4, nil], [1, 2, 3, nil, nil], [1, 2, nil, nil, nil], [1,
2, 3, 4, 5]]

a.transpose
=> [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, nil, 3], [4, nil, nil, 4], [nil,
nil, nil, 5]]

On Sat, May 1, 2010 at 8:59 PM, Pen T. [email protected] wrote:

5
how to get it ?

Posted via http://www.ruby-forum.com/.

You need to be more clear:

First your names are “text1” and “text2” but your data is not quoted
like
text would be. It is split with commas like an array would be, but it is
not
bracketed like an array would be, and you named it text.

Second, your desired data is unclear, the spacing is off so that it is
unclear which row the 4 belongs on, and the 5 seems to be on the wrong
side.
If this is what you actually desire, you need to explain the rules that
determine this output, if not, then you need to double check your input.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs