From: William James Date: 2007-09-08T05:20:11+09:00 Subject: Re: array handling advice On Sep 7, 12:38 pm, Chris McMahon wrote: > There is probably a simple way to do this, but I'm drawing a blank: > > I have an arbitrarily large input array, like > > input = ['a','b','c','d','e','f','g'] > > and three target arrays like > > targ_one = [] > targ_two = [] > targ_three = [] > > I want to deal out the elements of this array into three target arrays > so they end up like > > ['a','d','g'] > ['b','e'] > ['c','f'] > > It seems there should be an elegant way to do this, but I haven't hit > on it. Suggestions would be welcome. input = ['a','b','c','d','e','f','g'] def seq lo,hi,gap (0 .. ((hi-lo)/gap)).map{|n| n*gap + lo} end output = (0..2).map{|i| input.values_at( *seq(i,input.size-1,3) ) }