From: Colin Bartlett Date: 2009-05-19T00:49:18+09:00 Subject: Re: permute each element of a ragged array? Rick DeNatale: > On Mon, May 18, 2009 at 10:35 AM, Mark Thomas wrote: >> Not sure why the test must be as written, because the order doesn't >> fall in a logical pattern (as far as I can tell). > Exactly, I don't see a general way to see a pattern when the > assertions are expressed as indexed elements equaling specific values. Given the clarification, I think there is a pattern: the element of the first set is varying slowest in the examples, with the empty set being returned last, but I assume that that is not absolutely necessary? To summarise, using the example given, we have: * one non-recursive solution which varies the element of the first set slowest; two recursive (therefore more elegant) solutions: * one recursive solution (RDN) which varies the element of the first set fastest; * one recursive solution (MT) which varies the element of the first set slowest (returns array of strings rather than array of arrays, but easily modified?); All three produce the same results (albeit not in the same order) for: sets = [ %w( android hero ), %w( insane clown posse ), %w( phenomenauts ), ] But using: sets = [ %w( android ), %w( insane clown ) ] ruby 1.8.6 (2007-09-24 patchlevel 111) [i386-mswin32] [["android"], ["insane", "clown"]] non-recursive ["android", "insane"] ["android", "clown"] ["android"] ["insane"] ["clown"] [] RDN recursive ["android", "insane"] ["insane"] ["android", "clown"] ["clown"] ["android"] [] MT recursive "android insaneclown" "android" "insaneclown" ""