Perl Christmas Quiz

Robin Barker Robin.Barker at
Mon Dec 15 18:12:22 GMT 2008

My haskell solution:

import List (delete) 
intersection :: Eq a => [a] -> [a] -> [a]
intersection [] _ = []
intersection (x:xs) ys = if elem x ys then x: (intersection xs (delete x ys))
							else intersection xs ys

My Perl solution:

sub intersection {
    my ($a, $b) = @_;
    my %c;
    $c{$_}++ for @$b;
    return [ grep {$c{$_} and $c{$_}--} @$a ];

This e-mail and any attachments may contain confidential and/or
privileged material; it is for the intended addressee(s) only.
If you are not a named addressee, you must not use, retain or
disclose such information.

NPL Management Ltd cannot guarantee that the e-mail or any
attachments are free from viruses.

NPL Management Ltd. Registered in England and Wales. No: 2937881
Registered Office: Serco House, 16 Bartley Wood Business Park,
                   Hook, Hampshire, United Kingdom  RG27 9UY

More information about the mailing list