in reply to Re^5: Divide array of integers into most similar value halves
in thread Divide array of integers into most similar value halves

Sorry
It seems to do worse. Some of the elemenents appear if both of the resulting subarrays
  • Comment on Re^6: Divide array of integers into most similar value halves

Replies are listed 'Best First'.
Re^7: Divide array of integers into most similar value halves
by BrowserUk (Patriarch) on Sep 04, 2008 at 15:57 UTC

    Grr! Intersection & difference of arrays is something that ought to be in core.

    Looked in List::MoreUtils to no avail.

    I looked at cpan and downloaded Array::Utils but it can't handle duplicates.

    Looked at List::Compare, but it comes complete with the kitchen sink & waste disposal (aliased as Belfast Sink & waste bin) and calculates 20 different things under the guise of "initalising".

    Could you post an example of input array and expected outputs please.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      Sure!!! If
      @array = (40,17,40,30,40,25,40); is given

      something like

      @subarray1 = (40,40,30)
      @subarray2 = (40,40,17,25)

      should be returned.

      I guess you already have your own sources, but for intersection of arrays I always use a function from PerlFAQ 4:
      @union = @intersection = @difference = (); %count = (); foreach $element (@array1, @array2) { $count{$element}++ } foreach $element (keys %count) { push @union, $element; push @{ $count{$element} > 1 ? \@intersection : \@difference } +, $element; }

      Let me know if you need more examples, or what kind of them are you looking for