On Dec 15, 2008, at 10:04, "James Laver" <james.la...@gmail.com> wrote:
On Sun, Dec 14, 2008 at 3:15 PM, Avleen Vig <avl...@gmail.com> wrote:
On Fri, Dec 12, 2008 at 9:50 AM, Chris Jack <chris_j...@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))
:-)
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.