From: Aldric Giacomoni Date: 2009-12-18T02:37:23+09:00 Subject: Re: Unique combination of values from arrays Milo Thurston wrote: > Here's a problem for which I can't see an obvious solution, and hope > someone might have some suggestions. > > I have several arrays, each with a variety of text values in them. I > need to construct some strings consisting of each unique combination of > the arrays in order. Here's a very simple example: This is a little cleaner: def array_permutations array, index=0 result = [] if index == array.size result << "" return result end array[index].each do |element| array_permutations(array, index + 1).each do |x| result << "#{element} #{x}" end end result.map! { |string| string.strip } return result end one = ['one', two'] two = ['three', 'four'] three = ['five', 'six'] array_permutations [one, two, three] -- Posted via http://www.ruby-forum.com/.