in reply to Perl Golf-- testing array intersection
Hmmm.... 25 if you can't have duplicate values in the second array. 39 if you can.
(if it is allowed to return a list, 23 and 37. Remove 0+ from each.)
sub intersect{ @z{@x}=@x;0+grep$z{$_},@y # 1 2 #234567890123456789012345 }
sub intersect_dupes{ @a{@x}=@x;@b{@y}=@y;0+grep$a{$_},keys%b # 1 2 3 #23456789012345678901234567890123456789 }
|
|---|