From: Martin DeMello Date: 2006-11-12T17:36:13+09:00 Subject: Re: Splitting an array into quads and putting them back together again. On 11/12/06, CBlair1986 wrote: > and I can easily rotate those, but now I'm not sure on how to put them > back together like so: > > [a1][b1] > [a2][b2] > > If anyone knows a good way to do this, it would be greatly appreciated. require 'enumerator' class Array def |(other) self.zip(other).map {|a,b| a+b} end def /(other) self + other end end a1 = [[1,2],[5,6]] b1 = [[3,4],[7,8]] a2 = [[9,10],[13,14]] b2 = [[11,12],[15,16]] p (a1|b1)/(a2|b2) class Array def shape(cols) enum_slice(cols).map {|i| i.inject {|j, k| j|k}}.inject {|a, i| a/i} end end p [a1, b1, a2, b2].shape(2)