in reply to Perl Golf-- testing array intersection

Both your and Errto’s solutions violate your spec: they will ignore duplicate elements in @x, but they report duplicate matches in @y.

The best I’ve come up with that works correctly is 49 characters (or 51 if you care about the context issue).

sub aristotle { # 1 2 3 4 #234567890123456789012345678901234567890123456789 @_{@x}=(1)x@x;$_|=2for@_{@y};grep$_{$_}==3,keys%_ }

Makeshifts last the longest.

Replies are listed 'Best First'.
Re^2: Perl Golf-- testing array intersection
by Errto (Vicar) on Jan 30, 2006 at 22:17 UTC
    My interpretation of the spec allowed that behavior but ok, here's one at 45 chars that follows the duplicate rule:
    sub match { # 123456789012345678901234567890123456789012345 ++$c{$_}for@x;++$d{$_}for@y;grep$d{$_},keys%c }