Here is an outline of an algorithm you can adapt:
my %h; my $n=3; sub add{ my ($n,$v,@a)=@_; (%h < $n and not exists $h{$_} and $h{$_}=$v ) for @a }; add($n, # Allow $n unique elements 1, # This is the First array to be added # Numbers below are the contens of the array to be added 3,4,5,6,3,2,4,1); # First set of numbers $n+=$n; # Now increase the number of elements allowed add($n,2,4,3,2,7,8,2); # Second set of numbers print qq($_ => $h{$_} \n) for sort keys %h --OUTPUT--- 2 => 2 3 => 1 4 => 1 5 => 1 7 => 2 8 => 2
The VALUES of the hash indicate the source array it came from.

Yes - this can be optimized, and use of the global %h can be avoided - enhancements left as an exercise.

    ...each is assigned his own private delusion but he cannot see the baggage on his own back.


In reply to Re: Mutually Exclusive Elements by NetWallah
in thread Mutually Exclusive Elements by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.