Perl Christmas Quiz

Jasper jaspermccrea at gmail.com
Fri Dec 12 16:44:34 GMT 2008


2008/12/12 Peter Corlett <abuse at cabal.org.uk>:
> On Fri, Dec 12, 2008 at 01:18:24PM +0000, Hakim Cassimally wrote:
> [...]
>> The question isn't specific about how the output should look if it a key
>> doesn't appear in both arrays, or if n==m.
>
> It does. It asks for the "intersect", which is the set theory way of saying
> "those elements that appear in both sets, and no others".
>
> Here's my attempt:

> sub intersect{my%x;$x{$_}++for(@{+shift});grep{$x{$_}&&$x{$_}--}@{+shift};}

 sub routineX48 {my%b;s//1/for at b{@{+pop}};grep chop$b{$_},@{+pop}}

I'm sure there's a better way to get rid of the double conditional,
but TMTOWTDI.


-- 
Jasper


More information about the london.pm mailing list