Perl Christmas Quiz

Avleen Vig avleen at gmail.com
Sun Dec 14 15:15:03 GMT 2008


On Fri, Dec 12, 2008 at 9:50 AM, Chris Jack <chris_jack at msn.com> wrote:
> 3) Write a Perl function that takes two references to arrays and returns the intersect of them. If an entry appears n times in array 1 and m times in array 2, the output should list that entry min(n,m) times. Bonus mark for one line solutions.

In the spirit of sharing, I offer this solution, from your neighbours
in the Python community:

a = ['m', 'n', 'o', 'o', 'p', 'p', 'q']
b = ['n', 'p', 'q', 'r', 'r', 's']

def FindSetMatches(list1, list2):
  for i in set(list1).intersection(set(list2)):
    print '%s min(%s, %s)' % (i, list1.count(i), list2.count(i))


:-)


More information about the london.pm mailing list