From: "Simon Kröger" Date: 2005-08-31T20:39:41+09:00 Subject: Re: how to unflatten a flat-array SHIGETOMI, Takuhiko wrote: > greetings, William. i'm sorry, your way is beyond my light-weight brain. > > >>ary = [1,2,3,4,5,6,7,8] >>f=nil >>t=ary.partition{f=!f} >>p t[0].zip(t[1]) > > > but it works... > > $ irb > irb(main):001:0> ary = [1,2,3,4,5,6,7,8] > => [1, 2, 3, 4, 5, 6, 7, 8] > irb(main):002:0> f=nil > => nil > irb(main):003:0> t=ary.partition{f=!f} > => [[1, 3, 5, 7], [2, 4, 6, 8]] > irb(main):004:0> p t[0].zip(t[1]) > [[1, 2], [3, 4], [5, 6], [7, 8]] > => nil > > i'd like you use a terrestrial language, or beam me your universal > translator. :-) > Muhahaha... p ary.zip((0...ary.size).to_a).partition{|o|(o[1]%2).zero?}. map{|a|a.transpose[0]} erm, sorry, could not resist :) But transpose make the example above shorter (and perhaps even more readable): f=nil p ary.partition{f=!f}.transpose cheers Simon