On Feb 2, 4:04 pm, Thomas Hafner <tho... / hafner.NL.EU.ORG> wrote: > "William James" <w_a_x_... / yahoo.com> wrote/schrieb <1170361559.491476.96... / p10g2000cwp.googlegroups.com>: > > > Here's a shorter but slower way. > > > def cart_prod( *args ) > > args.inject([[]]){|old,lst| > > lst.inject([]){|new,e| > > new + old.map{|c| c.dup << e}}} > > end > > Wow, it's really short. Maybe it's not slower at all. Did you just > that? Or did you compare it actually? > > Regards > Thomas I tested it; it's slower. This one isn't quite as slow. def cart_prod( *args ) args.inject([[]]){|old,lst| new = [] lst.each{|e| new += old.map{|c| c.dup << e }} new } end