From: Paul Lutus Date: 2006-11-12T15:15:05+09:00 Subject: Re: Splitting an array into quads and putting them back together again. CBlair1986 wrote: > Hi all, I've got a question. A really quick, easy-to-answer question, > if I'm lucky ;) > > I have an array of arrays: > > a = [[ 1, 2, 3, 4], > [ 5, 6, 7, 8], > [ 9,10,11,12], > [13,14,15,16]] > > I've already borrowed code from the Matrix class to select sub-arrays > of this array: > > a1 = [[1,2],[5,6]] > b1 = [[3,4],[7,8]] > a2 = [[9,10],[13,14]] > b2 = [[11,12],[15,16]] > > 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] Perhaps it would be better if you specify exactly what you want, with all the numbers and brackets in place. Here is a first cut based on what you have said: #!/usr/bin/ruby -w a1 = [[1,2],[5,6]] b1 = [[3,4],[7,8]] a2 = [[9,10],[13,14]] b2 = [[11,12],[15,16]] c1 = [a1,b1].transpose.flatten d1 = [a2,b2].transpose.flatten p c1,d1 [1, 2, 3, 4, 5, 6, 7, 8] [9, 10, 11, 12, 13, 14, 15, 16] -- Paul Lutus http://www.arachnoid.com