From: Martin DeMello Date: 2005-08-07T23:51:08+09:00 Subject: Re: cartesian product Robert Klemme wrote: > > Note that it might be more memory efficient to write a iteration method: > > def cartprod(a,b) > a.each {|ae| b.each {|be| yield ae, be}} > end > > Then you can also do this if needed > > c=[] > cartprod(a,b) {|x,y| c << [x,y]} > > If you just need every combination once the iteration approach is more > efficient. Or even better, if block_given? yield ae, be else (c ||= []) << ae, be end martin