Perl Christmas Quiz
avleen at gmail.com
Mon Dec 15 13:22:49 GMT 2008
On Dec 15, 2008, at 10:04, "James Laver" <james.laver at gmail.com> wrote:
> On Sun, Dec 14, 2008 at 3:15 PM, Avleen Vig <avleen at gmail.com> wrote:
>> On Fri, Dec 12, 2008 at 9:50 AM, Chris Jack <chris_jack at msn.com>
>>> 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))
> Using other languages is really cheating.
Well duh. There were alreay multiple Perl solution out there. And I
didn't know a better one.
Plus I just wanted to be a snob with my four-line solution.
More information about the london.pm