note Zed_Lopez <p>I'm not sure about your requirements. I wrote a solution that produces</p> <code> [1,2,3] [3,4,7] [3,6,9] </code> <p>This seems more consistent with your stated requirements than your example results. 4 & 8 are equally common -- they appear twice in the arrays. 4 occurs before 8 in \$b, thus the elements appear in \$b's order of insertion.</p> <p>At any rate, my algorithm was:</p> <ol><li>Traverse all the arrays, counting how many of each element appear.</li> <li>Sort the results in order of ascending frequency and assign it to @frequency.</li> <li>Take the last of these (i.e. most frequent, or tied for most frequent, and thus common to all) and assign it to \$common.</li> <li>Die with an error message if \$common < the number of arrays -- there wasn't really an element common to all.</li> <li>Start building the results for each array:<ol> <li>First, assign \$common.</li> <li>Then, for each element in @frequency, test if that element is present in the current array. If it is, assign it to the results for this array. Do this X-1 times (assigning \$common took care of one element.)</li> <li>Sort this array's results.</li></ol></li> <li>Push an arrayref for this array's results on your final results array.</li></ol> <p><b>Updated:</b> my unstated assumption in the above was that that code would be in a subroutine to be called like so:</p> <code> my (\$a_, \$b_, \$c_) = mutually_exclusive(\$X, \$a, \$b, \$c); </code> 411973 411973