SonOfLilit
7/10/2007 1:17:00 PM
Oi...
How could I have misread so badly?
I'm sorry, I had this so cool elegant hammer and I guess I immediately
saw a nail :P
Aur
On 7/10/07, Robert Klemme <shortcutter@googlemail.com> wrote:
> 2007/7/10, SonOfLilit <sonoflilit@gmail.com>:
> > a = [[1, 4, 7, 10, 13], [2, 5, 8, 11, 14], [3, 6, 9, 12, 15]]
> >
> > a0 = a.shift
> >
> > p a0.zip(*a)
>
> This outputs
>
> [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12], [13, 14, 15]]
>
> Which is not what the OP wanted according to his first posting (see
> quote below). Still it's a nice approach!
>
> > to grok this, ri Array#zip
> >
> > On 7/10/07, Kaps Lok <jocubeit@gmail.com> wrote:
> > > Is there an elegant (maybe a one-liner) for repacking:
> > >
> > > [[1, 4, 7, 10, 13], [2, 5, 8, 11, 14], [3, 6, 9, 12, 15]]
> > >
> > > to?
> > >
> > > [[1, 4, 7], [10, 13, 2], [5, 8, 11], [14, 3, 6], [9, 12, 15]]
> > >
> > > So rather than having 3 arrays each with 5 elements, I get five arrays
> > > of 3 elements each...
> > >
> > > the only way I can see to do this is by looping the array, and creating
> > > new arrays.
> > >
> > > Any help would be much appreciated.
>
> Kind regards
>
> robert
>
>