From: walter a kehowski Date: 2005-08-08T07:36:08+09:00 Subject: Re: cartesian product Hello, The following is not in the spirit of previous comments class Array def cartprod(b) c=[] each {|ae| b.each {|be| c << [ae, be] } } c.collect! {|ce| ce.flatten} end #cartprod end #Array a=[[1,2,3],[4,5,6],[7,8,9]] c=a[0] as=a.slice(1..a.length-1) as.each {|ase| c=c.cartprod(ase) } c.each {|ce| ce.each {|x| print x," " }; print "\n" } Would the following be desirable? If cartprod has two or more arguments, do the usual thing, but if it has just one, it takes the cartesian product with that argument, i.e, cartprod(a) gives cartprod(a,a) or a.cartprod(a), etc. And thanks for all the suggestion so far. I usually just play around with Perl but got $#@% fatigue. It was a toss-up between Python and Ruby so here I am. Walter Kehowski