From: Suraj Kurapati Date: 2009-10-20T04:14:10+09:00 Subject: Re: Dynamic nested each in ruby 1.8.7? Suraj Kurapati wrote: > Aldric Giacomoni wrote: >> Would this help at all? >> http://trevoke.net/blog/2008/12/20/lexicographic-permutations-in-ruby/ > > I did not understand how to use that simpler permutations() method: > Any suggestions? Never mind, I figured it out: >> result = [] => [] >> permutations ["0", "1", "2"] do |val| result << val end => ["0", "1", "2"] >> pp result [["0", "1", "2"], ["0", "2", "1"], ["1", "0", "2"], ["1", "2", "0"], ["2", "0", "1"], ["2", "1", "0"]] => nil Pretty cool. An improvement would be to return an Enumerator. -- Posted via http://www.ruby-forum.com/.