### PS3: Problem 3 » Solutions

May. 5th, 2010 02:34 pm**aranthe**posting in

**intro_to_cs**

#### PS3: Problem 3 » Solutions

# Problem 3: constrainedMatchPair, constrainedMatchPairR (recursive) def constrainedMatchPair( firstMatch, secondMatch, length ): allN = () for n in firstMatch: tryK = n + length + 1 if tryK in secondMatch: allN += n, return allN def constrainedMatchPairR( firstMatch, secondMatch, length ): if not firstMatch: return () else: tryK = firstMatch[-1] + length + 1 if tryK in secondMatch: return (firstMatch[-1],) + constrainedMatchPairR(firstMatch[:-1], secondMatch, length) else: return constrainedMatchPairR(firstMatch[:-1], secondMatch, length)