From: walter a kehowski Date: 2005-08-13T06:31:11+09:00 Subject: Re: cartesian product - next to last version Hello, Yielding the values is certainly a good idea, but it makes the code a lot bigger. Anyhow, here is the recursive, yielding version. def cartprod(base, *others) if block_given? if others.empty? base.each{|a| yield [a]} else base.each do | a | cartprod(*others) do | b | yield [a, *b] end end end nil # <--Why? else return base.map{|a|[a]} if others.empty? others = cartprod(*others) base.inject([]) { | r, a | others.inject(r) { | r, b | r << ([a, *b]) } } end end -- http://ruby.brian-schroeder.de/ ## Question: Why the nil?