in reply to Difference arrays.

my @p = (1,1,1,1,1,2,2,2,3,3,4,5,6); my @q = (1,2,3,4,5,6 ); # my @p = (43, 43, 44); # my @q = (43, 43); my %q; $q{$_}++ for @q; my @r = grep { --$q{$_} < 0; } @p; print join (',', @r), "\n";

Replies are listed 'Best First'.
Re^2: Difference arrays.
by BrowserUk (Patriarch) on Sep 04, 2008 at 20:30 UTC
Re^2: Difference arrays.
by Skeeve (Parson) on Sep 04, 2008 at 19:36 UTC

    Similar idea like mine above , but much, much better than I did it! ++ and ++ could I vote twice!


    s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
    +.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e
Re^2: Difference arrays.
by journey (Monk) on Sep 06, 2008 at 02:34 UTC
Re^2: Difference arrays.
by Skeeve (Parson) on Sep 04, 2008 at 21:27 UTC

    Big bug

    Just found it when I was examining kyle's solution.

    swap p and q and your routine will fail!

    Sorry! Not a bug! My mistake!


    s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
    +.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e

      I noticed that your solution is symmetric because it has the abs in it. However I was taking BrowserUk by the word: "those in the first not in the second".

      Given the restriction "one a proper subset of the other", it does not matter, and our solutions print essentially the same elements (maybe in a different order).

        Something I learned again: Keep your big mouth shut until you read a second time ;-) So Sorry for crying too early. MINE has the bug. I've added comments above.


        s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
        +.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e